#include <iostream>
#include <fstream>
#include <string>
#include "pb_cfg_act.pb.h"

#include "CActMgr.h"
#include "../mainctrl.h"
#include "MsgGM.pb.h"
#include "CEnemyAtkCity.h"
#include "../clan/CClanMgr.h"
#include "../cmdinner/CCmdSplendidActClanRank.h"
#include "../cmdinner/CCmdActInnerCmd.h"
#include "../cmdinner/CCmdInnerActTitle.h"
#include "MsgSplendidAct.pb.h"
#include "../clan/CClanBattleMgr.h"
#include "MsgAct.pb.h"
#include "CActCfg.h"
#include "CMagicDoorMgr.h"
#include "CDaySignCfg.h"
#include "CDayWishCfg.h"
#include "CManorBattleCfg.h"

template<>
bool CTRankArray<CGoldCardAct, MAX_SPLENDID_GOLD_CARD_MAX_RANK>::IsSame(
        CGoldCardAct&a, CGoldCardAct&b) const
{
    return a.uiGID == b.uiGID;
}

template<>
int CTRankArray<CGoldCardAct, MAX_SPLENDID_GOLD_CARD_MAX_RANK>::CmpFunc(
        CGoldCardAct&a, CGoldCardAct&b) const
{
    return (a.iGoldCardCount - b.iGoldCardCount);
}

template<>
bool CTRankArray<CSDRecordUnit, MAX_SPLENDID_SD_RECORD_COUNT>::IsSame(
        CSDRecordUnit& stA, CSDRecordUnit& stB) const
{
    return (stA._iUpdateTime == stB._iUpdateTime);
}

template<>
int CTRankArray<CSDRecordUnit, MAX_SPLENDID_SD_RECORD_COUNT>::CmpFunc(
        CSDRecordUnit& stA, CSDRecordUnit& stB) const
{
    if (stA._iUpdateTime > stB._iUpdateTime)
    {
        return 1;
    }
    else if (stA._iUpdateTime < stB._iUpdateTime)
    {
        return -1;
    }

    return 0;
}

template<>
bool CTRankArray<CSDChargeUnit, MAX_SPLENDID_SD_RANK_COUNT>::IsSame(
        CSDChargeUnit& stA, CSDChargeUnit& stB) const
{
    return (stA._uiGID == stB._uiGID);
}

template<>
int CTRankArray<CSDChargeUnit, MAX_SPLENDID_SD_RANK_COUNT>::CmpFunc(
        CSDChargeUnit& stA, CSDChargeUnit& stB) const
{
    if (stA._iGold > stB._iGold)
    {
        return 1;
    }
    else if (stA._iGold < stB._iGold)
    {
        return -1;
    }

    return 0;
}

int CActMgr::ParseTime(const string& strDateTime, int& iDateTime, char chType)
{
    if (strDateTime.length() <= 0)
    {
        return 0;
    }

    iDateTime = 0;//要放在string串长度判断之后不然出去的默认值变成0有些情况希望保持初始值-1

    bool bInValid = false;
    if (strDateTime.length() == 19 && CActCfgData::ACT_CFG_DATE_TIME == chType)	// YYYY-mm-dd HH:MM:SS
    {
        time_t t_time;
        struct tm stTm;

        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(0, 4).c_str(), true);
        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(5, 2).c_str(), true);
        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(8, 2).c_str(), true);
        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(11, 2).c_str(), true);
        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(14, 2).c_str(), true);
        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(17, 2).c_str(), true);

        if (bInValid)
        {
            CT_ERROR(("string verify time %s error!",strDateTime.c_str()));
            return ERROR_ACT_ERROR_CFG;
        }

        stTm.tm_year = strtol(strDateTime.substr(0, 4).c_str(), NULL, 10) - 1900;
        stTm.tm_mon = strtol(strDateTime.substr(5, 2).c_str(), NULL, 10) - 1;
        stTm.tm_mday = strtol(strDateTime.substr(8, 2).c_str(), NULL, 10);
        stTm.tm_hour = strtol(strDateTime.substr(11, 2).c_str(), NULL, 10);
        stTm.tm_min = strtol(strDateTime.substr(14, 2).c_str(), NULL, 10);
        stTm.tm_sec = strtol(strDateTime.substr(17, 2).c_str(), NULL, 10);

        t_time = mktime(&stTm);

        if (t_time < 0)
        {
            CT_ERROR(("parse time %s error!",strDateTime.c_str()));
            return ERROR_ACT_ERROR_CFG;
        }

        iDateTime = (int)(t_time & 0x7FFFFFFF);
    }
    else if (strDateTime.length() == 5 && CActCfgData::ACT_CFG_SEG_TIME == chType) // HH:MM
    {
        int iHour = 0;
        int iMinu = 0;

        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(0, 2).c_str(), true);
        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(3, 2).c_str(), true);

        if (bInValid)
        {
            CT_ERROR(("string verify time %s error!",strDateTime.c_str()));
            return ERROR_ACT_ERROR_CFG;
        }

        iHour = strtol(strDateTime.substr(0, 2).c_str(), NULL, 10);
        iMinu = strtol(strDateTime.substr(3, 2).c_str(), NULL, 10);

        if (iHour >= 24 || iMinu >= 60)
        {
            CT_ERROR(("string verify time %s error!",strDateTime.c_str()));
            return ERROR_ACT_ERROR_CFG;
        }

        iDateTime = iHour * 3600 + iMinu * 60;
    }
    else if (strDateTime.length() == 4 && CActCfgData::ACT_CFG_SEG_TIME == chType) // H:MM
    {
        int iHour = 0;
        int iMinu = 0;

        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(0, 1).c_str(), true);
        bInValid |= !CTStringUtils::StrToIntVerify(strDateTime.substr(2, 2).c_str(), true);

        if (bInValid)
        {
            CT_ERROR(("string verify time %s error!",strDateTime.c_str()));
            return ERROR_ACT_ERROR_CFG;
        }

        iHour = strtol(strDateTime.substr(0, 1).c_str(), NULL, 10);
        iMinu = strtol(strDateTime.substr(2, 2).c_str(), NULL, 10);

        if (iHour >= 10 || iMinu >= 60)
        {
            CT_ERROR(("string verify time %s error!",strDateTime.c_str()));
            return ERROR_ACT_ERROR_CFG;
        }

        iDateTime = iHour * 3600 + iMinu * 60;
    }
    else if (CActCfgData::ACT_CFG_REL_OPEN == chType)
    {
        std::string sTime = strDateTime;
        if ('@' != sTime[0]) //距离开服天数
        {
            return ERROR_ACT_ERROR_CFG;
        }
        
        int iZoneOpenTime = CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData._iZoneOpenTime;        
        CTStringUtils::Remove(sTime, '@');
        iDateTime  = CTTimeUtils::GetDayBeginSec(iZoneOpenTime) + (atoi(sTime.c_str()))* 86400;     
    }
    else
    {
        CT_ERROR(("unknow format time %s error!",strDateTime.c_str()));
        return ERROR_ACT_ERROR_CFG;
    }

    return 0;
}

int CActMgr::ParseSegTime(CActCfgData& stCfgData, const string& strSegStart,
        const string& strSegStop)
{
    int iRet = 0;
    CActSegTime stSegTime;

    iRet = ParseTime(strSegStart, stSegTime._iStart,
            CActCfgData::ACT_CFG_SEG_TIME);
    CT_RETURN(iRet);

    iRet = ParseTime(strSegStop, stSegTime._iStop,
            CActCfgData::ACT_CFG_SEG_TIME);
    CT_RETURN(iRet);

    if (stSegTime._iStart > 0 &&
        stSegTime._iStop > 0 &&
        !stCfgData.AddSegTime(stSegTime))
    {
        CT_ERROR(("add segment time error!"));
        return ERROR_ACT_ERROR_CFG;
    }

    return 0;
}

int CActMgr::ParseSegTime(CSystemNoticeCfgData& stCfgData,
        const string& strSegStart, const string& strSegStop)
{
    int iRet = 0;
    CActSegTime stSegTime;

    iRet = ParseTime(strSegStart, stSegTime._iStart,
        CActCfgData::ACT_CFG_SEG_TIME);
    CT_RETURN(iRet);

    iRet = ParseTime(strSegStop, stSegTime._iStop,
        CActCfgData::ACT_CFG_SEG_TIME);
    CT_RETURN(iRet);

    if (stSegTime._iStart > 0 &&
        stSegTime._iStop > 0 &&
        !stCfgData.AddSegTime(stSegTime))
    {
        CT_ERROR(("add segment time error!"));
        return ERROR_ACT_ERROR_CFG;
    }

    return 0;
}

int CActMgr::LoadConfig(const char* szCfgPath)
{
    int iRet = 0;
    int iIndex = 0;

    if (szCfgPath == NULL)
    {
        CT_ERROR(("Act Cfg Path is null"));
        return RET_SYSTEM_FAIL;
    }

    pb_cfg_act stActCfg;
    std::fstream stFileInput(szCfgPath, std::ios::in | std::ios::binary);
    if (!stActCfg.ParseFromIstream(&stFileInput))
    {
        CT_ERROR(("Failed to Parse ActCfg!"));
        return RET_SYSTEM_FAIL;
    }

    ClearNotifyAndUpdateTime();//先简单清理

    int iStartTime = 0;
    int iStopTime = 0;
    int iUpdateTime = 0;

    //活动配置
    CActCfgData stCfgData;
    for (int i = 0; i < stActCfg.act_cfg_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_act_cfg_unit& stActUnit = stActCfg.act_cfg_rows(i);

        iStartTime = 0;
        iStopTime = 0;
        iUpdateTime = -1;//比较特殊为了兼容0点可以更新这里初始值为-1
        stCfgData.Clear();

        stCfgData.SetResID((short)stActUnit.res_id());
        stCfgData.SetSceneID((short)stActUnit.scene_id());
        stCfgData.SetType((char)stActUnit.type());
        stCfgData.SetAllDayOpen((stActUnit.all_day_open() == 0 ? false : true));

        if (stCfgData.GetSceneID() > 0)
        {
            iIndex = CMainCtrl::m_pstMain->m_stSceneMgr.FindSceneCfg(
                    stCfgData.GetSceneID());
            if (iIndex < 0)
            {
                CT_WARNING(("act(%d) scene(%d) empty!",
                            stCfgData.GetResID(),stCfgData.GetSceneID()));
                return ERROR_SCENE_EMPTY_CFG;
            }
        }

        if (stActUnit.has_segment_start_1())
        {
            if (!stActUnit.has_segment_stop_1())
            {
                CT_ERROR(("has segment start time 1 but don't have stop time!"));
                return ERROR_ACT_ERROR_CFG;
            }

            iRet = ParseSegTime(stCfgData, stActUnit.segment_start_1(), stActUnit.segment_stop_1());
            CT_RETURN(iRet);
        }

        if (stActUnit.has_segment_start_2())
        {
            if (!stActUnit.has_segment_stop_2())
            {
                CT_ERROR(("has segment start time 2 but don't have stop time!"));
                return ERROR_ACT_ERROR_CFG;
            }

            iRet = ParseSegTime(stCfgData, stActUnit.segment_start_2(), stActUnit.segment_stop_2());
            CT_RETURN(iRet);
        }

        if (stActUnit.has_segment_start_3())
        {
            if (!stActUnit.has_segment_stop_3())
            {
                CT_ERROR(("has segment start time 3 but don't have stop time!"));
                return ERROR_ACT_ERROR_CFG;
            }

            iRet = ParseSegTime(stCfgData, stActUnit.segment_start_3(), stActUnit.segment_stop_3());
            CT_RETURN(iRet);
        }

        if (!stCfgData.IsValidSegTime())
        {
            CT_ERROR(("segment time invalid!"));
            return ERROR_ACT_ERROR_CFG;
        }

        if (stActUnit.has_start_time())
        {
            char chType = CActCfgData::ACT_CFG_DATE_TIME;
            if ('@' == stActUnit.start_time()[0])
            {
                chType = CActCfgData::ACT_CFG_REL_OPEN;
            }

            iRet = ParseTime(stActUnit.start_time(), iStartTime, chType);
            CT_RETURN(iRet);

            if (!stActUnit.has_stop_time())
            {
                CT_ERROR(("has border start time but don't have border stop time!"));
                return ERROR_ACT_ERROR_CFG;
            }

            if ('@' == stActUnit.stop_time()[0])
            {
                chType = CActCfgData::ACT_CFG_REL_OPEN;
            }
            else
            {
                chType = CActCfgData::ACT_CFG_DATE_TIME;
            }

            iRet = ParseTime(stActUnit.stop_time(), iStopTime, chType);
            CT_RETURN(iRet);

            if (((0 == iStartTime || 0 == iStopTime) && iStartTime != iStopTime) ||
                ((0 != iStartTime || 0 != iStopTime) && iStopTime <= iStartTime))
            {
                CT_ERROR(("start time(%d) or stop time(%d) error!",iStartTime,iStopTime));
                return ERROR_ACT_ERROR_CFG;
            }

            if (iStartTime > 0 && iStopTime > 0 && iStartTime < iStopTime)
            {
                stCfgData.SetStartTime(iStartTime);
                stCfgData.SetStopTime(iStopTime);
            }
        }

        if (stActUnit.has_update_time())
        {
            iRet = ParseTime(stActUnit.update_time(), iUpdateTime,
                CActCfgData::ACT_CFG_SEG_TIME);
            CT_RETURN(iRet);

            stCfgData.SetUpdateTime(iUpdateTime);
        }

        if (stActUnit.tip_id() > 0)
        {
            stCfgData.SetTipID(stActUnit.tip_id());
            stCfgData.SetLastTip(CMainCtrl::m_pstMain->m_iNow);//必须置为当前值
        }

        if (stActUnit.has_start_days() &&
                strlen(stActUnit.start_days().c_str()) > 0)
        {
            std::string sOpenDays = stActUnit.start_days();
            const std::string sDel = ",";
            std::vector<std::string> vOpenDays;

            CTStringUtils::Split(sOpenDays, sDel, vOpenDays);
            for (unsigned int i = 0; i < vOpenDays.size(); ++i)
            {                    
                stCfgData.SetWeekOpenDay((unsigned char)atoi(vOpenDays[i].c_str()));
                CT_TRACE(("stCfgData: %d, %d", stCfgData.GetResID(), stCfgData.GetWeekOpenDays()));
            }
        }
        else
        {
            stCfgData.SetAllWeekOpen();
        }

        iRet = _stActCfg.AddConfig(stCfgData);
        CT_RETURN(iRet);
    }

    //读取开采魔晶配置
    for (int i = 0; i < stActCfg.mine_crystal_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_mine_crystal_unit & stMineUnit = stActCfg.mine_crystal_rows(i);
        CMineDropItemConfig stConfig;

        unsigned char ucMineType = stMineUnit.mine_type();
        if ((ucMineType <= MINE_TYPE_NONE)
            || (ucMineType > MINE_TYPE_MAX))
        {
            CT_ERROR(("%d", ucMineType));

            return ERROR_MINE_CRYSTAL_CONFIG;
        }

        stConfig._ucItemType = stMineUnit.item_type();
        if ((stConfig._ucItemType != ITEM_TYPE_CRYSTAL)
             && (stConfig._ucItemType != ITEM_TYPE_JEWEL)
             && (stConfig._ucItemType != ITEM_TYPE_CRYSTAL_FRAG)
             && (stConfig._ucItemType != ITEM_TYPE_SOLVENT)
             && (stConfig._ucItemType != ITEM_TYPE_MATERIAL)
             && (stConfig._ucItemType != ITEM_TYPE_GIFT))
        {
            CT_ERROR(("%d", stConfig._ucItemType));
            return ERROR_MINE_CRYSTAL_CONFIG;
        }

        stConfig._usItemId = stMineUnit.item_id();
        stConfig._szItemSubType.Set("%s", stMineUnit.subtype().c_str());
        stConfig._ucCount = stMineUnit.count();
        iRet = _stMineConfig.AddConfig(ucMineType, stConfig, stMineUnit.drop_rate());
        if (iRet)
        {
            CT_ERROR(("%d,%d", stMineUnit.drop_rate(), iRet));
            return ERROR_MINE_CRYSTAL_CONFIG;
        }

        //检查概率和是否为100%
        if ((i+1) == stActCfg.mine_crystal_rows_size())
        {
            for (int k = 1; k < MINE_TYPE_MAX; k++)
            {
                int iRateSum = _stMineConfig._stMineDrop._stMineDrop[k-1].GetMax();
                if (COMM_MOD != iRateSum)
                {
                    CT_ERROR(("%d,%d", k, iRateSum));
                    return ERROR_MINE_CRYSTAL_CONFIG;
                }
            }
        }
    }

    //怪物攻城战配置
    for (int i = 0; i < stActCfg.enemy_atk_city_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_enemy_atk_city_unit & stConfigUnit = stActCfg.enemy_atk_city_rows(i);

        CEnemyAtkCityEnemyConfigData stConfig;
        stConfig._ucRound = stConfigUnit.round_id();
        stConfig._uiMonsterGroupID = stConfigUnit.monster_group_id();
        stConfig._ucMonsterGroupCount = stConfigUnit.monster_count();
        stConfig._uiKillMonsterBonusGiftID = stConfigUnit.kill_gift_id();

        iRet = _stEnemyAtkCityConfig.AddConfig(stConfig);
        CHECK_RETURN(iRet);
    }

    //怪物攻城战奖励配置
    for (int i = 0; i < stActCfg.eac_bonus_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_eac_bonus_unit & stConfigUnit = stActCfg.eac_bonus_rows(i);

        CEnemyAtkCityBonusConfigData stConfig;
        stConfig._iRank = stConfigUnit.rank();
        stConfig._iRoleRankGiftID = stConfigUnit.role_gift_id();
        stConfig._iAcaRankGiftID = stConfigUnit.aca_gift_id();

        iRet = _stEnemyAtkCityBonusConfig.AddConfig(stConfig);
        CHECK_RETURN(iRet);
    }

    //精彩活动配置
    for (int i = 0; i < stActCfg.splendid_act_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_splendid_act_unit & stConfigUnit = stActCfg.splendid_act_rows(i);

        CZoneData& stZoneData = CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;

        CSplendidActConfigData stConfigData;
        string sTmp;
        stConfigData._iActID = stConfigUnit.act_id();

        if (stZoneData._iZoneCombineTime == 0 //未合过服
            || (stConfigUnit.combine_begin_time() == "" && stConfigUnit.combine_end_time() == ""))  //未配置合服时间
        {
            GetSplendidActTime(stConfigUnit.begin_time().c_str(), stConfigData._iBeginTime, stZoneData._iZoneOpenTime);
            GetSplendidActTime(stConfigUnit.end_time().c_str(), stConfigData._iEndTime, stZoneData._iZoneOpenTime);

            //计算是否要延期活动
            CTSizeString<1024> szTmp;
            szTmp.Set("%s", stConfigUnit.begin_time().c_str());
            if (szTmp.GetDataLen() == 0 || szTmp[0] == '+')  //只有相对时间才需要计算
            {
                int iActReleaseTime = 0;
                GetSplendidActTime(stConfigUnit.act_release_time().c_str(), iActReleaseTime, stZoneData._iZoneOpenTime);
                
                int iNewEndTime = iActReleaseTime + (stConfigData._iEndTime - stConfigData._iBeginTime);

                //int iZoneOpenDayTime = CTTimeUtils::GetDayBeginSec(stZoneData._iZoneOpenTime);

                if (iActReleaseTime <= stConfigData._iBeginTime)
                {
                    stConfigData._iBeginTime = stConfigData._iBeginTime;
                    stConfigData._iEndTime = stConfigData._iEndTime;
                }
                else if(iActReleaseTime > stConfigData._iBeginTime && iActReleaseTime <= stConfigData._iEndTime)
                {
                    stConfigData._iBeginTime = stConfigData._iBeginTime;
                    stConfigData._iEndTime = iNewEndTime;
                }
                else if(iActReleaseTime > stConfigData._iEndTime)
                {
                    stConfigData._iBeginTime = iActReleaseTime;
                    stConfigData._iEndTime = iNewEndTime;
                }
                else
                {
                    return RET_SYS_ERROR;
                }
               

                /*
                if (iZoneOpenDayTime < iActReleaseTime && stConfigData._iBeginTime < iActReleaseTime)
                {
                    int iAheadSecs = iActReleaseTime - stConfigData._iBeginTime;
                    stConfigData._iBeginTime = iActReleaseTime;
                    stConfigData._iEndTime += iAheadSecs;
                }
                */
            }
        }
        else
        {
            GetSplendidActTime(stConfigUnit.combine_begin_time().c_str(), stConfigData._iBeginTime, stZoneData._iZoneCombineTime);
            GetSplendidActTime(stConfigUnit.combine_end_time().c_str(), stConfigData._iEndTime, stZoneData._iZoneCombineTime);

            //计算是否要延期活动
            CTSizeString<1024> szTmp;
            szTmp.Set("%s", stConfigUnit.combine_begin_time().c_str());
            if (szTmp.GetDataLen() == 0 || szTmp[0] == '+')  //只有相对时间才需要计算
            {
                int iActReleaseTime = 0;
                GetSplendidActTime(stConfigUnit.act_release_time().c_str(), iActReleaseTime, stZoneData._iZoneOpenTime);

                int iZoneCombineTime = CTTimeUtils::GetDayBeginSec(stZoneData._iZoneCombineTime);

                if (iZoneCombineTime < iActReleaseTime && stConfigData._iBeginTime < iActReleaseTime)
                {
                    int iAheadSecs = iActReleaseTime - stConfigData._iBeginTime;
                    stConfigData._iBeginTime = iActReleaseTime;
                    stConfigData._iEndTime += iAheadSecs;
                }
            }
        }

        stConfigData._bHasChildAct = (stConfigUnit.has_child_act() == 1);
        stConfigData._iParentActID = stConfigUnit.parent_act_id();
        stConfigData._szTargets.Set("%s", stConfigUnit.target().c_str());
        stConfigData._szBonus.Set("%s", stConfigUnit.gift_id().c_str());
        stConfigData._bIsSplendidAct = (stConfigUnit.is_splendid_act() == 1);

        iRet = _stSplendidActConfig.AddConfig(stConfigData);
        CHECK_RETURN(iRet);

        switch (stConfigData._iActID)
        {
        case SPLENDID_ACT_ID_7: // 魔晶合成赢幸运
            {
                //初始化等级配置
                std::string sTmp = stConfigData._szTargets();
                const std::string sDel = ",";
                std::vector<std::string> vContents;

                CTStringUtils::Split(sTmp, sDel, vContents);

                if (vContents.size() != MAX_SPLENDID_CRYCOMBINE_LEVEL_COUNT)
                {
                    CT_ERROR(("target error: %d", vContents.size()));
                    return RET_SYS_ERROR;
                }
                
                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astCryCombineLevels.AddOneItem(atoi(vContents[i].c_str()));
                }

                //初始化奖励配置
                vContents.clear();
                sTmp = stConfigData._szBonus();
                CTStringUtils::Split(sTmp, sDel, vContents);

                if (vContents.size() != MAX_SPLENDID_CRYCOMBINE_LEVEL_COUNT)
                {
                    CT_ERROR(("bonus error: %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astCryCombineBonus.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;
        case SPLENDID_ACT_ID_8:
            {
                //获取排名个数
                _stSplendidActConfigDetail._iClanRankCount = atoi(stConfigData._szTargets());
                if (_stSplendidActConfigDetail._iClanRankCount <= 0 
                    || _stSplendidActConfigDetail._iClanRankCount > MAX_SPLENDID_CLAN_RANK_COUNT)
                {
                    CT_ERROR(("clan rank count error %d", _stSplendidActConfigDetail._iClanRankCount));
                    return RET_SYS_ERROR;
                }
                
                //分析奖励
                std::string sTmp = stConfigData._szBonus();
                std::string sDel = ";";
                std::vector<std::string> vContents;

                CTStringUtils::Split(sTmp, sDel, vContents);

                if (vContents.size() != 2) //奖励只有两段
                {
                    CT_ERROR(("clan rank bonus error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                std::string sMaterBonus = vContents[0];
                std::string sMemberBonus = vContents[1];

                //族长奖励
                sDel = ",";
                vContents.clear();
                CTStringUtils::Split(sMaterBonus, sDel, vContents);

                if ((int)vContents.size() != _stSplendidActConfigDetail._iClanRankCount)
                {
                    CT_ERROR(("clan rank mater bonus error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astClanMasterBonus.AddOneItem(atoi(vContents[i].c_str()));
                }

                //成员奖励
                sDel = ",";
                vContents.clear();
                CTStringUtils::Split(sMemberBonus, sDel, vContents);

                if ((int)vContents.size() != _stSplendidActConfigDetail._iClanRankCount)
                {
                    CT_ERROR(("clan rank mater bonus error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astClanMemberBonus.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;
        case SPLENDID_ACT_ID_9:
            {
                //解析目标
                std::string sTmp = stConfigData._szTargets();
                std::string sDel = ",";
                std::vector<std::string> vContents;

                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() == 0 || vContents.size() > MAX_SPLENDID_EAC_TARGETS_COUNT)
                {
                    CT_ERROR(("eac targets error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astEacTargets.AddOneItem(atoi(vContents[i].c_str()));
                }

                //解析奖励
                sTmp = stConfigData._szBonus();
                sDel = ",";
                vContents.clear();
                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() != _stSplendidActConfigDetail._astEacTargets.Size())
                {
                    CT_ERROR(("eac bonus error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astEacBonus.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;
        case SPLENDID_ACT_ID_10:
            {
                //解析目标
                std::string sTmp = stConfigData._szTargets();
                std::string sDel = ",";
                std::vector<std::string> vContents;

                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() == 0 || vContents.size() > MAX_BUY_GOLD_CONFIG_COUNT)
                {
                    CT_ERROR(("buy gold targets error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astBuyGoldConfigID.AddOneItem(atoi(vContents[i].c_str()));
                }

                //解析奖励
                sTmp = stConfigData._szBonus();
                sDel = ",";
                vContents.clear();
                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() != _stSplendidActConfigDetail._astBuyGoldConfigID.Size())
                {
                    CT_ERROR(("buy gold bonus error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astBuyGoldGBonus.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;
        case SPLENDID_ACT_ID_11: //中秋活动
            {
                //解析目标
                std::string sTmp = stConfigData._szTargets();
                std::string sDel = ",";
                std::vector<std::string> vContents;

                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() != MAX_SPLENDID_ZQ_GIFT_COUNT)
                {
                    CT_ERROR(("zhong qiu act target error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astZQGiftBeginTime.AddOneItem(atoi(vContents[i].c_str()));
                }

                //解析奖励
                sTmp = stConfigData._szBonus();
                sDel = ",";
                vContents.clear();
                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() != MAX_SPLENDID_ZQ_GIFT_COUNT)
                {
                    CT_ERROR(("zhong qiu act gift error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astZQGiftID.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;

        case SPLENDID_ACT_ID_12:    //消费排行
            {
                //解析目标
                std::string sTmp = stConfigData._szTargets();
                std::string sDel = ",";
                std::vector<std::string> vContents;

                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() != MAX_SPLENDID_PAY_RANK_COUNT)
                {
                    CT_ERROR(("pay rank target error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astPayRankBonusTarget.AddOneItem(atoi(vContents[i].c_str()));
                }

                //解析奖励
                sTmp = stConfigData._szBonus();
                sDel = ",";
                vContents.clear();
                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() != MAX_SPLENDID_PAY_RANK_COUNT)
                {
                    CT_ERROR(("pay rank gift error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astPayRankGift.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;

        case SPLENDID_ACT_ID_13: //国庆登录有奖
            {
                _stSplendidActConfigDetail._iGQLoginBeginTime = atoi(stConfigData._szTargets()); //奖励开始时间

                //解析奖励
                std::string sTmp = stConfigData._szBonus();
                std::string sDel = ",";
                std::vector<std::string> vContents;

                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() != MAX_SPLENDID_GQ_LOGIN_DAYS)
                {
                    CT_ERROR(("gq bonus error %d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astGQLoginGift.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;

        case SPLENDID_ACT_ID_14: //国庆集卡
            {
                //解析目标
                std::string sTmp = stConfigData._szTargets();
                std::string sDel = ",";
                std::vector<std::string> vContents;

                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() > MAX_SPLENDID_GQ_GET_CARD_BONUS_COUNT)
                {
                    CT_ERROR(("%d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    std::string sTmp2 = vContents[i];
                    std::string sDel2 = "+";
                    std::vector<std::string> vTargets;

                    CTStringUtils::Split(sTmp2, sDel2, vTargets);

                    if ((int)vTargets.size() > MAX_SPLENDID_GQ_GET_CARD_COUNT)
                    {
                        CT_ERROR(("%d", vTargets.size()));
                        return RET_SYS_ERROR;
                    }   

                    CSplendidActConfigDetail::T_GQ_GET_CARD_TARGET stTargets;
                    for (int i = 0; i < (int)vTargets.size(); ++i)
                    {
                        stTargets.AddOneItem(atoi(vTargets[i].c_str()));
                    }
                    
                    _stSplendidActConfigDetail._astGQGetCardTargets.AddOneItem(stTargets);
                }

                //解析奖励
                sTmp = stConfigData._szBonus();
                sDel = ",";
                vContents.clear();
                CTStringUtils::Split(sTmp, sDel, vContents);

                if ((int)vContents.size() != _stSplendidActConfigDetail._astGQGetCardTargets.Size())
                {
                    CT_ERROR(("%d", vContents.size()));
                    return RET_SYS_ERROR;
                }

                for (int i = 0; i < (int)vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astGQGetCardGift.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;

        case SPLENDID_ACT_ID_16: //感恩节活动
            {
                //解析目标
                std::string sTmp = stConfigData._szTargets();
                std::string sDel = ",";
                std::vector<std::string> vContents;
                CTStringUtils::Split(sTmp, sDel, vContents);

                if (vContents.size() != 4)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }

                _stSplendidActConfigDetail._iGanEnSendHammerByGold = atoi(vContents[0].c_str());
                _stSplendidActConfigDetail._iGanEnSendGiftByGold = atoi(vContents[1].c_str());
                _stSplendidActConfigDetail._iGanEnSendMountByGold = atoi(vContents[2].c_str());
                _stSplendidActConfigDetail._iGanEnSendCryGiftByGold = atoi(vContents[3].c_str());
                
                //解析奖励
                sTmp = stConfigData._szBonus();
                sDel = ",";
                vContents.clear();
                CTStringUtils::Split(sTmp, sDel, vContents);

                if (vContents.size() != 6)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }

                _stSplendidActConfigDetail._iGanEnGiftID1 = atoi(vContents[0].c_str());
                _stSplendidActConfigDetail._iGanEnGiftID2 = atoi(vContents[1].c_str());
                _stSplendidActConfigDetail._iGanEnGiftID3 = atoi(vContents[2].c_str());
                _stSplendidActConfigDetail._iGanEnGiftID4 = atoi(vContents[3].c_str());
                _stSplendidActConfigDetail._iGanEnGiftID5 = atoi(vContents[4].c_str());
                _stSplendidActConfigDetail._iGanEnGiftID6 = atoi(vContents[5].c_str());
            }
            break;

        case SPLENDID_ACT_ID_17: //转盘
            {
                std::string sTmp = stConfigData._szBonus();
                std::string sDel = ";";
                std::vector<std::string> vContents;

                CTStringUtils::Split(sTmp, sDel, vContents);
                if (vContents.size() != 3)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }

                std::string sGift1 = vContents[0];
                std::string sGift2 = vContents[1];
                std::string sGift3 = vContents[2];

                //宝箱礼包
                vContents.clear();
                sDel = ",";
                CTStringUtils::Split(sGift1, sDel, vContents);
                if (vContents.size() != 6)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }

                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astZPGift1.AddOneItem(atoi(vContents[i].c_str()));
                }
                
                //一介
                vContents.clear();
                sDel = ",";
                CTStringUtils::Split(sGift2, sDel, vContents);
                if (vContents.size() != 8)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }

                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astZPGift2.AddOneItem(atoi(vContents[i].c_str()));
                }

                //二介
                vContents.clear();
                sDel = ",";
                CTStringUtils::Split(sGift3, sDel, vContents);
                if (vContents.size() != 8)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }

                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astZPGift3.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;

        case SPLENDID_ACT_ID_18:	//双蛋
            {
                std::string sTmp = stConfigData._szBonus();
                std::string sDel = ";";
                std::vector < std::string > vContents;
                
                CTStringUtils::Split(sTmp, sDel, vContents);
                if (vContents.size() != 2)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
                
                std::string sGift1 = vContents[0];
                std::string sGift2 = vContents[1];
                
                //开出大奖
                vContents.clear();
                sDel = ",";
                CTStringUtils::Split(sGift1, sDel, vContents);
                if (vContents.size() != 4)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
                
                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astSDGift1.AddOneItem(atoi(vContents[i].c_str()));
                }
                
                //没有开出大奖
                vContents.clear();
                sDel = ",";
                CTStringUtils::Split(sGift2, sDel, vContents);
                if (vContents.size() != 4)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
                
                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._astSDGift2.AddOneItem(atoi(vContents[i].c_str()));
                }
            }
            break;

        case SPLENDID_ACT_ID_19:	//摇摇乐活动
            {
                std::string sTmp = stConfigData._szBonus();
                std::string sDel = ";";
                std::vector < std::string > vContents;
                std::vector < std::string > vUnits;
                
                CTStringUtils::Split(sTmp, sDel, vContents);
                if (vContents.size() != 3)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
                
                std::string sGift1 = vContents[0];
                std::string sGift2 = vContents[1];
                std::string sGift3 = vContents[2];
                
                //第一段 符石价格
                vContents.clear();
                sDel = ",";
                CTStringUtils::Split(sGift1, sDel, vContents);
                if (vContents.size() != 1)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
                
                int iLimitGold = 0;
                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    iLimitGold = atoi(vContents[i].c_str());
                    if (iLimitGold <= 0)
                    {
                        CT_ERROR((""));
                        return RET_SYS_ERROR;
                    }
                    _stSplendidActConfigDetail._iRockGold = iLimitGold;
                }
                 
                //第二段 用于随机的礼包ID
                vContents.clear();
                sDel = ",";
                CTStringUtils::Split(sGift2, sDel, vContents);
                if (vContents.size() != MAX_SPLENDID_ROCK_RANDOM_GIFT)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
                
                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    _stSplendidActConfigDetail._aiRockRandomGift.AddOneItem(atoi(vContents[i].c_str()));
                }
                
                //第三段 积分值_兑换礼包_限制次数
                //用于兑换的次数限制 0 表示不限制 1~255 表示限制次数 使用unsigned char存储
                vContents.clear();
                sDel = ",";
                CTStringUtils::Split(sGift3, sDel, vContents);
                if (vContents.size() != MAX_SPLENDID_ROCK_EXCHANGE_GIFT)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
                
                sDel = "_";
                int iLimitNum = 0;
                for (unsigned int i = 0; i < vContents.size(); ++i)
                {
                    vUnits.clear();
                    CTStringUtils::Split(vContents[i], sDel, vUnits);
                    if (vUnits.size() != 3)
                    {
                        CT_ERROR((""));
                        return RET_SYS_ERROR;
                    }

                    iLimitNum = atoi(vUnits[2].c_str());
                    if (iLimitNum < 0 || iLimitNum > 255)
                    {
                        CT_ERROR((""));
                        return RET_SYS_ERROR;
                    }

                    _stSplendidActConfigDetail._aiRockExchangeScore.AddOneItem(atoi(vUnits[0].c_str()));
                    _stSplendidActConfigDetail._aiRockExchangeGift.AddOneItem(atoi(vUnits[1].c_str()));
                    _stSplendidActConfigDetail._aiRockExchangeMask.AddOneItem(iLimitNum);
                }

                for (int i = 0; i < _stSplendidActConfigDetail._aiRockRandomInt.GetCount(); ++i)
                {
                    _stSplendidActConfigDetail._aiRockRandomInt.AddOneItem(CT_RANDOM_NUM->GetRand(MAX_SPLENDID_ROCK_NUM_COUNT)+1);
                }
            }
            break;

        case SPLENDID_ACT_ID_20:	//领红包活动
            {
                std::string sTmp = stConfigData._szTargets();
                std::string sDel = ",";
                std::vector < std::string > vContents;
                
                CTStringUtils::Split(sTmp, sDel, vContents);
                if (vContents.size() != 2)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
                
                GetSplendidActTime(vContents[0].c_str(),
                    _stSplendidActConfigDetail._iRedPacketGatherStart, stZoneData._iZoneOpenTime);

                GetSplendidActTime(vContents[1].c_str(),
                    _stSplendidActConfigDetail._iRedPacketGatherStop, stZoneData._iZoneOpenTime);

                if (_stSplendidActConfigDetail._iRedPacketGatherStart <= 0 ||
                    _stSplendidActConfigDetail._iRedPacketGatherStart >= _stSplendidActConfigDetail._iRedPacketGatherStop)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
                if (_stSplendidActConfigDetail._iRedPacketGatherStart < stConfigData._iEndTime)
                {
                    CT_ERROR((""));
                    return RET_SYS_ERROR;
                }
            }
            break;

        default:
            break;
        }
    }

    //活动状态配置
    CActStatusCfgData stStatusCfgData;
    for (int i = 0; i < stActCfg.act_status_cfg_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_act_status_cfg_unit& stStatusAct 
            = stActCfg.act_status_cfg_rows(i);

        stStatusCfgData.Clear();

        stStatusCfgData.SetActID((short)stStatusAct.act_id());
        stStatusCfgData.SetMerlinID(stStatusAct.merlin_id());
        stStatusCfgData.SetInspireID(stStatusAct.inspire_id());
        stStatusCfgData.SetDeadID(stStatusAct.dead_id());
        stStatusCfgData.SetCoolingID(stStatusAct.cooling_id());

        if (stStatusCfgData.GetActID() > 0)
        {
            iIndex = CMainCtrl::m_pstMain->m_stActMgr.FindActCfg(
                stStatusCfgData.GetActID());
            if (iIndex < 0)
            {
                CT_ERROR(("act(%d) config empty!",
                            stStatusCfgData.GetActID()));
                return ERROR_ACT_EMPTY_CFG;
            }
        }
    
        iRet = CMainCtrl::m_pstMain->m_stStatusMgr.IsValidStatusID(
            stStatusCfgData.GetMerlinID());
        CT_RETURN(iRet);

        iRet = CMainCtrl::m_pstMain->m_stStatusMgr.IsValidStatusID(
            stStatusCfgData.GetInspireID());
        CT_RETURN(iRet);

        iRet = CMainCtrl::m_pstMain->m_stStatusMgr.IsValidStatusID(
            stStatusCfgData.GetDeadID());
        CT_RETURN(iRet);

        iRet = CMainCtrl::m_pstMain->m_stStatusMgr.IsValidStatusID(
            stStatusCfgData.GetCoolingID());
        CT_RETURN(iRet);

        iRet = CMainCtrl::m_pstMain->m_stActMgr.AddActStatusCfg(
            stStatusCfgData);
        CT_RETURN(iRet);
    }

    //家族战奖励配置
    for (int i = 0; i < stActCfg.clan_battle_bonus_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_clan_battle_bonus_unit& stConfigUnit
            = stActCfg.clan_battle_bonus_rows(i);

        CClanBattleBonusConfigData stConfigData;
        stConfigData._iRank = stConfigUnit.rank();
        stConfigData._iRoleRankGiftID = stConfigUnit.role_gift_id();
        stConfigData._iClanRankGiftID = stConfigUnit.clan_gift_id();

        iRet = _stClanBattleBonusConfig.AddConfig(stConfigData);
        CHECK_RETURN(iRet);
    }

    //金字塔活动
    for (int i = 0; i < stActCfg.pyramid1_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_pyramid1_unit& stConfigUnit
            = stActCfg.pyramid1_rows(i);

        CPyramidBonusConfigData stConfigData;
        stConfigData._iPyramidID = stConfigUnit.id();
        stConfigData._iWinBonusGiftID = stConfigUnit.win_gift_id();
        stConfigData._iKillAllBonusGiftID = stConfigUnit.all_kill_gift_id();

        iRet = _stPyramidConfig.AddBonusConfig(stConfigData);
        CHECK_RETURN(iRet);
    }

    for (int i = 0; i < stActCfg.pyramid2_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_pyramid2_unit& stConfigUnit
            = stActCfg.pyramid2_rows(i);

        CPyramidMonsterConfigData stConfigData;
        stConfigData._iPyramidID = stConfigUnit.id();
        stConfigData._iIndex = stConfigUnit.index();
        stConfigData._iMonsterGroupID = stConfigUnit.monster_group_id();
        stConfigData._iMonsterLevel = stConfigUnit.monster_level();

        unsigned char ucDropItemType = (unsigned char)(stConfigUnit.normal_drop_item_type1() & 0x7F);
        if (ucDropItemType != ITEM_TYPE_NULL)
        {
            CInstanceDropItemConfigData stDropItemConfigData;
            stDropItemConfigData._ucDropItemType = ucDropItemType;
            stDropItemConfigData._usDropItemConfigID = stConfigUnit.normal_drop_item_id1();
            stDropItemConfigData._szDropItemSubType.Set("%s", stConfigUnit.normal_drop_item_subtype1().c_str());
            stDropItemConfigData._uiDropRate = (unsigned int)(stConfigUnit.normal_drop_item_rate1() & 0x7FFFFFFF);
            stDropItemConfigData._iDropCount = stConfigUnit.normal_drop_item_count1();

            stConfigData._astMonsterDrop.AddOneItem(stDropItemConfigData);
        }

        ucDropItemType = (unsigned char)(stConfigUnit.normal_drop_item_type2() & 0x7F);
        if (ucDropItemType != ITEM_TYPE_NULL)
        {
            CInstanceDropItemConfigData stDropItemConfigData;
            stDropItemConfigData._ucDropItemType = ucDropItemType;
            stDropItemConfigData._usDropItemConfigID = stConfigUnit.normal_drop_item_id2();
            stDropItemConfigData._szDropItemSubType.Set("%s", stConfigUnit.normal_drop_item_subtype2().c_str());
            stDropItemConfigData._uiDropRate = (unsigned int)(stConfigUnit.normal_drop_item_rate2() & 0x7FFFFFFF);
            stDropItemConfigData._iDropCount = stConfigUnit.normal_drop_item_count2();

            stConfigData._astMonsterDrop.AddOneItem(stDropItemConfigData);
        }

        ucDropItemType = (unsigned char)(stConfigUnit.normal_drop_item_type3() & 0x7F);
        if (ucDropItemType != ITEM_TYPE_NULL)
        {
            CInstanceDropItemConfigData stDropItemConfigData;
            stDropItemConfigData._ucDropItemType = ucDropItemType;
            stDropItemConfigData._usDropItemConfigID = stConfigUnit.normal_drop_item_id3();
            stDropItemConfigData._szDropItemSubType.Set("%s", stConfigUnit.normal_drop_item_subtype3().c_str());
            stDropItemConfigData._uiDropRate = (unsigned int)(stConfigUnit.normal_drop_item_rate3() & 0x7FFFFFFF);
            stDropItemConfigData._iDropCount = stConfigUnit.normal_drop_item_count3();

            stConfigData._astMonsterDrop.AddOneItem(stDropItemConfigData);
        }

        ucDropItemType = (unsigned char)(stConfigUnit.normal_drop_item_type4() & 0x7F);
        if (ucDropItemType != ITEM_TYPE_NULL)
        {
            CInstanceDropItemConfigData stDropItemConfigData;
            stDropItemConfigData._ucDropItemType = ucDropItemType;
            stDropItemConfigData._usDropItemConfigID = stConfigUnit.normal_drop_item_id4();
            stDropItemConfigData._szDropItemSubType.Set("%s", stConfigUnit.normal_drop_item_subtype4().c_str());
            stDropItemConfigData._uiDropRate = (unsigned int)(stConfigUnit.normal_drop_item_rate4() & 0x7FFFFFFF);
            stDropItemConfigData._iDropCount = stConfigUnit.normal_drop_item_count4();

            stConfigData._astMonsterDrop.AddOneItem(stDropItemConfigData);
        }

        ucDropItemType = (unsigned char)(stConfigUnit.normal_drop_item_type5() & 0x7F);
        if (ucDropItemType != ITEM_TYPE_NULL)
        {
            CInstanceDropItemConfigData stDropItemConfigData;
            stDropItemConfigData._ucDropItemType = ucDropItemType;
            stDropItemConfigData._usDropItemConfigID = stConfigUnit.normal_drop_item_id5();
            stDropItemConfigData._szDropItemSubType.Set("%s", stConfigUnit.normal_drop_item_subtype5().c_str());
            stDropItemConfigData._uiDropRate = (unsigned int)(stConfigUnit.normal_drop_item_rate5() & 0x7FFFFFFF);
            stDropItemConfigData._iDropCount = stConfigUnit.normal_drop_item_count5();

            stConfigData._astMonsterDrop.AddOneItem(stDropItemConfigData);
        }

        iRet = _stPyramidConfig.AddMonsterConfig(stConfigData);
        CHECK_RETURN(iRet);
    }
    
    //活动系统提示配置
    CSystemNoticeCfgData stSysNoticeCfgData;
    for (int i = 0; i < stActCfg.system_notice_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_system_notice_unit& stSysNoticeUnit =
            stActCfg.system_notice_rows(i);

        stSysNoticeCfgData.Clear();

        stSysNoticeCfgData.SetID(stSysNoticeUnit.id());
        stSysNoticeCfgData.SetInterval(stSysNoticeUnit.second_interval());
        stSysNoticeCfgData.SetLastDay(stSysNoticeUnit.last_day());

        if (stSysNoticeUnit.has_segment_start_1())
        {
            if (!stSysNoticeUnit.has_segment_stop_1())
            {
                CT_ERROR(("has seg start time 1 but don't have stop time!"));
                return ERROR_SYSTEM_NOTICE_ERROR_CFG;
            }

            iRet = ParseSegTime(stSysNoticeCfgData,
                stSysNoticeUnit.segment_start_1(),
                stSysNoticeUnit.segment_stop_1());
            CT_RETURN(iRet);
        }

        if (stSysNoticeUnit.has_segment_start_2())
        {
            if (!stSysNoticeUnit.has_segment_stop_2())
            {
                CT_ERROR(("has seg start time 2 but don't have stop time!"));
                return ERROR_SYSTEM_NOTICE_ERROR_CFG;
            }

            iRet = ParseSegTime(stSysNoticeCfgData,
                stSysNoticeUnit.segment_start_2(),
                stSysNoticeUnit.segment_stop_2());
            CT_RETURN(iRet);
        }

        if (stSysNoticeUnit.has_segment_start_3())
        {
            if (!stSysNoticeUnit.has_segment_stop_3())
            {
                CT_ERROR(("has seg start time 3 but don't have stop time!"));
                return ERROR_SYSTEM_NOTICE_ERROR_CFG;
            }

            iRet = ParseSegTime(stSysNoticeCfgData,
                stSysNoticeUnit.segment_start_3(),
                stSysNoticeUnit.segment_stop_3());
            CT_RETURN(iRet);
        }

        if (stSysNoticeUnit.has_segment_start_4())
        {
            if (!stSysNoticeUnit.has_segment_stop_4())
            {
                CT_ERROR(("has seg start time 4 but don't have stop time!"));
                return ERROR_SYSTEM_NOTICE_ERROR_CFG;
            }

            iRet = ParseSegTime(stSysNoticeCfgData,
                stSysNoticeUnit.segment_start_4(),
                stSysNoticeUnit.segment_stop_4());
            CT_RETURN(iRet);
        }

        if (stSysNoticeUnit.has_segment_start_5())
        {
            if (!stSysNoticeUnit.has_segment_stop_5())
            {
                CT_ERROR(("has seg start time 5 but don't have stop time!"));
                return ERROR_SYSTEM_NOTICE_ERROR_CFG;
            }

            iRet = ParseSegTime(stSysNoticeCfgData,
                stSysNoticeUnit.segment_start_5(),
                stSysNoticeUnit.segment_stop_5());
            CT_RETURN(iRet);
        }

        if (!stCfgData.IsValidSegTime())
        {
            CT_ERROR(("segment time invalid!"));
            return ERROR_SYSTEM_NOTICE_ERROR_CFG;
        }

        iRet = _stSystemNoticeCfg.AddConfig(stSysNoticeCfgData);
        CT_RETURN(iRet);
    }

    //每日签到活动配置
    CDaySignCfg& stDaySignCfg =
        CMainCtrl::m_pstMain->m_stDaySignMgr.GetDaySignCfg();
    stDaySignCfg.Clear();
    for (int i = 0; i < stActCfg.day_sign_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_day_sign_unit& stDaySignUnit =
            stActCfg.day_sign_rows(i);

        if (stDaySignUnit.continue_num() > 0 &&
                stDaySignUnit.continue_gift() > 0)
        {
            stDaySignCfg.AddContinueData(stDaySignUnit.continue_num(),
                (unsigned int)stDaySignUnit.continue_gift());
        }

        if (stDaySignUnit.accumulate_num() > 0 &&
                stDaySignUnit.accumulate_gift() > 0)
        {
            stDaySignCfg.AddAccumulateData(stDaySignUnit.accumulate_num(),
                (unsigned int)stDaySignUnit.accumulate_gift());
        }
    }

    iRet = stDaySignCfg.CheckDaySignCfg();
    CT_RETURN(iRet);

    //每日许愿活动配置 以及 登录奖励活动配置
    CDayWishCfg& stDayWishCfg =
        CMainCtrl::m_pstMain->m_stDayWishMgr.GetDayWishCfg();
    stDayWishCfg.Clear();
    CDayWishCfgData stDayWishCfgData;
    for (int i = 0; i < stActCfg.day_wish_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_day_wish_unit& stDayWishUnit =
            stActCfg.day_wish_rows(i);

        stDayWishCfgData.Clear();

        stDayWishCfgData.SetID(stDayWishUnit.id());
        stDayWishCfgData.SetItemType(stDayWishUnit.item_type());
        stDayWishCfgData.SetItemID(stDayWishUnit.item_id());
        stDayWishCfgData.SetItemNum(stDayWishUnit.item_num());

        if (stDayWishUnit.login_item_type_1() > 0 &&
            stDayWishUnit.login_item_id_1() >= 0 &&
            stDayWishUnit.login_item_num_1() > 0)
        {
            stDayWishCfgData.AddLoginItem(stDayWishUnit.login_item_type_1(),
                stDayWishUnit.login_item_num_1(),
                stDayWishUnit.login_item_id_1());
        }
        if (stDayWishUnit.login_item_type_2() > 0 &&
            stDayWishUnit.login_item_id_2() >= 0 &&
            stDayWishUnit.login_item_num_2() > 0)
        {
            stDayWishCfgData.AddLoginItem(stDayWishUnit.login_item_type_2(),
                stDayWishUnit.login_item_num_2(),
                stDayWishUnit.login_item_id_2());
        }
        if (stDayWishUnit.login_item_type_3() > 0 &&
            stDayWishUnit.login_item_id_3() >= 0 &&
            stDayWishUnit.login_item_num_3() > 0)
        {
            stDayWishCfgData.AddLoginItem(stDayWishUnit.login_item_type_3(),
                stDayWishUnit.login_item_num_3(),
                stDayWishUnit.login_item_id_3());
        }
        if (stDayWishUnit.login_item_type_4() > 0 &&
            stDayWishUnit.login_item_id_4() >= 0 &&
            stDayWishUnit.login_item_num_4() > 0)
        {
            stDayWishCfgData.AddLoginItem(stDayWishUnit.login_item_type_4(),
                stDayWishUnit.login_item_num_4(),
                stDayWishUnit.login_item_id_4());
        }
        if (stDayWishUnit.login_item_type_5() > 0 &&
            stDayWishUnit.login_item_id_5() >= 0 &&
            stDayWishUnit.login_item_num_5() > 0)
        {
            stDayWishCfgData.AddLoginItem(stDayWishUnit.login_item_type_5(),
                stDayWishUnit.login_item_num_5(),
                stDayWishUnit.login_item_id_5());
        }
        if (stDayWishUnit.login_item_type_6() > 0 &&
            stDayWishUnit.login_item_id_6() >= 0 &&
            stDayWishUnit.login_item_num_6() > 0)
        {
            stDayWishCfgData.AddLoginItem(stDayWishUnit.login_item_type_6(),
                stDayWishUnit.login_item_num_6(),
                stDayWishUnit.login_item_id_6());
        }
        if (stDayWishUnit.login_item_type_7() > 0 &&
            stDayWishUnit.login_item_id_7() >= 0 &&
            stDayWishUnit.login_item_num_7() > 0)
        {
            stDayWishCfgData.AddLoginItem(stDayWishUnit.login_item_type_7(),
                stDayWishUnit.login_item_num_7(),
                stDayWishUnit.login_item_id_7());
        }

        iRet = stDayWishCfg.AddConfig(stDayWishCfgData);
        CT_RETURN(iRet);
    }

    //新手目标
    for (int i = 0; i < stActCfg.newbie_task_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_newbie_task_unit& stConfigUnit
            = stActCfg.newbie_task_rows(i);

        CNewbieTaskConfigDetailData stConfigData;
        stConfigData._iTaskID = stConfigUnit.task_id();
        stConfigData._iDay = stConfigUnit.day();

        stConfigData._iTargetID = stConfigUnit.target_id();
        stConfigData._iTargetData = stConfigUnit.target_data();

        CDropItemData stDropItemData;
        stDropItemData._ucItemType = stConfigUnit.bonus_type();
        stDropItemData._usItemConfigID = stConfigUnit.bonus_id();
        stDropItemData._iItemCount = stConfigUnit.bonus_count();
        stConfigData.stDropItem.Drop(stDropItemData);

        iRet = _stNewbieTaskConfig.AddTaskConfig(stConfigData);
        CHECK_RETURN(iRet);
    }

    for (int i = 0; i < stActCfg.newbie_task2_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_newbie_task2_unit& stConfigUnit
            = stActCfg.newbie_task2_rows(i);

        CNewbieTaskDayConfigData stConfigData;
        stConfigData._iDay = stConfigUnit.day();

        CDropItemData stDropItemData;
        stDropItemData._ucItemType = stConfigUnit.bonus_type1();
        stDropItemData._usItemConfigID = stConfigUnit.bonus_id1();
        stDropItemData._iItemCount = stConfigUnit.bonus_count1();
        stConfigData.stDropItem.Drop(stDropItemData);

        stDropItemData._ucItemType = stConfigUnit.bonus_type2();
        stDropItemData._usItemConfigID = stConfigUnit.bonus_id2();
        stDropItemData._iItemCount = stConfigUnit.bonus_count2();
        stConfigData.stDropItem.Drop(stDropItemData);

        iRet = _stNewbieTaskConfig.AddDayConfig(stConfigData);
        CHECK_RETURN(iRet);
    }

    //宝箱争夺战
    for (int i = 0; i < stActCfg.fight_for_box_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_fight_for_box_unit& stConfigUnit =
            stActCfg.fight_for_box_rows(i);
        
        iRet = _stFightForBoxConfig.AddConfig(stConfigUnit);
        CT_RETURN(iRet);
    }

    //一战到底
    CFightEndCfgData stFightEndCfgData;
    for (int i = 0; i < stActCfg.fight_end_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_fight_end_unit& stConfigUnit =
            stActCfg.fight_end_rows(i);

        stFightEndCfgData.Clear();
        
        stFightEndCfgData.SetLevel(stConfigUnit.level());

        if (stConfigUnit.item_type_1() > 0 && stConfigUnit.item_num_1() > 0)
        {
            stFightEndCfgData.AddDropItem(
                (unsigned char)stConfigUnit.item_type_1(),
                (unsigned short)stConfigUnit.item_id_1(),
                stConfigUnit.item_num_1());
        }

        if (stConfigUnit.item_type_2() > 0 && stConfigUnit.item_num_2() > 0)
        {
            stFightEndCfgData.AddDropItem(
                (unsigned char)stConfigUnit.item_type_2(),
                (unsigned short)stConfigUnit.item_id_2(),
                stConfigUnit.item_num_2());
        }

        iRet = _stFightEndConfig.AddLevelConfig(stFightEndCfgData);
        CT_RETURN(iRet);
    }

    //开服特卖
    for (int i = 0; i < stActCfg.new_zone_sales_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_new_zone_sales_unit & stConfigUnit =
                                stActCfg.new_zone_sales_rows(i);

        CDropItemData stItemData;
        stItemData._ucItemType = stConfigUnit.item_type();
        stItemData._usItemConfigID = stConfigUnit.item_id();
        stItemData._iItemCount = stConfigUnit.item_cnt();
        
        int iPrice = 0;
        int iRet = CMainCtrl::m_pstMain->m_stItemMgr.GetItemPrice(stItemData._ucItemType, stItemData._usItemConfigID,
                              (unsigned short)stItemData._iItemCount, ITEM_BUY_PRICE_GOLD, iPrice);
        if (iRet)
        {
            CT_ERROR(("%d, %d, %d", iRet, stItemData._ucItemType, stItemData._usItemConfigID));
            return iRet;
        }

        if (1 == stConfigUnit.type())
        {
            CNewZoneSalesItem stItem;
            stItem._iRealCost = stConfigUnit.real_price();
            stItem._iInitCost = stConfigUnit.init_price();

            stItem._stItem = stItemData;

            iRet = _stNewZoneSalesConfig.AddItemConfig(stItem);
            CHECK_RETURN(iRet);
        }
        
        if (2 == stConfigUnit.type())
        {
            _stNewZoneSalesConfig._stBonus = stItemData;
        }        
    }

    //领地战奖励配置
    CManorBattleCfg& stManorBattleCfg =
        CMainCtrl::m_pstMain->m_stManorBattleMgr.GetManorBattleCfg();
    stManorBattleCfg.Clear();
    CManorBattleCfgData stManorBattleCfgData;
    for (int i = 0; i < stActCfg.manor_battle_rows_size(); ++i)
    {
        const pb_cfg_act_pb_cfg_manor_battle_unit& stManorBUnit =
            stActCfg.manor_battle_rows(i);

        stManorBattleCfgData.Clear();

        stManorBattleCfgData.SetID(stManorBUnit.id());

        if (stManorBUnit.item_type_1() > 0 && stManorBUnit.item_id_1() >= 0 &&
            stManorBUnit.item_num_1() > 0)
        {
            stManorBattleCfgData.AddItem(stManorBUnit.item_type_1(),
                stManorBUnit.item_num_1(), stManorBUnit.item_id_1());
        }
        if (stManorBUnit.item_type_2() > 0 && stManorBUnit.item_id_2() >= 0 &&
            stManorBUnit.item_num_2() > 0)
        {
            stManorBattleCfgData.AddItem(stManorBUnit.item_type_2(),
                stManorBUnit.item_num_2(), stManorBUnit.item_id_2());
        }

        iRet = stManorBattleCfg.AddConfig(stManorBattleCfgData);
        CT_RETURN(iRet);
    }

    return 0;
}

bool CActMgr::IsActOpen(short shActID)
{
    int iIndex;
    iIndex = FindActCfg(shActID);
    if (iIndex < 0)
    {
        CT_WARNING(("act(%d) config empty!",shActID));
        return false;
    }
    CActCfgData& stActCfgData = GetActCfg(iIndex);
    return stActCfgData.IsActOpen();
}

void CActMgr::SetActClose(short shActID, bool bChangeEndTime)
{
    //强制活动关闭需要notify前端
    int iIndex = FindActCfg(shActID);
    if (iIndex < 0)
    {
        CT_ERROR(("force close act(%d) config empty!",shActID));
        return;
    }
    CActCfgData& stActCfgData = GetActCfg(iIndex);

    ClearNotifyAndUpdateTime();//先简单清理

    if (bChangeEndTime)
    {
        stActCfgData.SetStat(CActCfgData::ACT_OBJ_STAT_FORCE_CLOSE,
            stActCfgData.GetBeginTime(), CMainCtrl::m_pstMain->m_iNow);
    }
    else
    {
        stActCfgData.SetStat(CActCfgData::ACT_OBJ_STAT_FORCE_CLOSE,
            stActCfgData.GetBeginTime(), stActCfgData.GetEndTime());
    }

    ActStatChange();
}

int CActMgr::GetBeginTime(short shActID)
{
    int iIndex = FindActCfg(shActID);
    if (iIndex < 0)
    {
        CT_WARNING(("act(%d) config empty!",shActID));
        return 0;
    }
    CActCfgData& stActCfgData = GetActCfg(iIndex);
    return stActCfgData.GetBeginTime();
}

int CActMgr::GetEndTime(short shActID)
{
    int iIndex = FindActCfg(shActID);
    if (iIndex < 0)
    {
        CT_WARNING(("act(%d) config empty!",shActID));
        return 0;
    }
    CActCfgData& stActCfgData = GetActCfg(iIndex);
    return stActCfgData.GetEndTime();
}

int CActMgr::GetStopTime(short shActID)
{
    int iIndex = FindActCfg(shActID);
    if (iIndex < 0)
    {
        CT_WARNING(("act(%d) config empty!",shActID));
        return 0;
    }
    CActCfgData& stActCfgData = GetActCfg(iIndex);
    return stActCfgData.GetStopTime();
}

void CActMgr::RefreshAct()
{
    if (CMainCtrl::m_pstMain->m_iNow <= _iLastTime)
    {
        return;
    }

    ClearNotifyAndUpdateTime();//先简单清理

    _stActCfg.RefreshAct();
    _iLastTime = CMainCtrl::m_pstMain->m_iNow;

    ActStatChange();

    DealActTips();

    DealActTimer();

    DealSysStop();

    _stSystemNoticeCfg.RefreshSystemNotice();
    DealSystemNotice();
}

void CActMgr::ActStatChange()
{
    int iIndex = 0;
    for (int i = 0; i < GetNotifyActSize(); ++i)
    {
        iIndex = FindActCfg(GetNotifyAct(i));
        if (iIndex < 0)
        {
            CT_WARNING(("act refresh act(%d) config empty",GetNotifyAct(i)));
            continue;
        }

        CActCfgData& stActCfgData = GetActCfg(iIndex);

        //活动开启
        if (stActCfgData.IsAutoOpen() || stActCfgData.IsForceOpen())
        {
            switch (stActCfgData.GetResID())
            {
            case ACT_ID_WORLD_BOSS:
                {
                    CMainCtrl::m_pstMain->m_stWorldBossMgr.ActOpen(
                        stActCfgData);
                }
                break;
            case ACT_ID_GRAN_BOSS://格兰学院BOSS活动ID
            case ACT_ID_SLEN_BOSS://斯林学院BOSS活动ID
            case ACT_ID_RAVAN_BOSS://拉文学院BOSS活动ID
            case ACT_ID_HUFF_BOSS://霍奇学院BOSS活动ID
                {
                    CMainCtrl::m_pstMain->m_stAcademyBossMgr.ActOpen(
                        stActCfgData);
                }
                break;
            case ACT_ID_CLAN_BATTLE:
                {
                    CMainCtrl::m_pstMain->m_stClanBattleMgr.SetBegin(
                        CMainCtrl::m_pstMain->m_iNow);
                }
                break;
            case ACT_ID_WEEKEND_SHOP:
                {
                    MsgTips stTips;
                    stTips.set_type(1037);
                    CMainCtrl::m_pstMain->SendOnlineTips(stTips);
                }
                break;
            case ACT_ID_ENEMY_ATK_CITY:
                {
                    CMainCtrl::m_pstMain->m_stEnemyAtkCityMgr.SetBegin(CMainCtrl::m_pstMain->m_iNow);
                    CMainCtrl::m_pstMain->m_stRewardBackMgr.SetActOpen(
                        ACT_ID_ENEMY_ATK_CITY,
                        CMainCtrl::m_pstMain->m_stArenaMgr.GetWorldBossLevel());
                }
                break;
            case ACT_ID_FIGHT_END:
                {
                    CMainCtrl::m_pstMain->m_stFightEndMgr.ActOpen(stActCfgData);
                }
                break;
            case ACT_ID_MANOR_BATTLE:
                {
                    CMainCtrl::m_pstMain->m_stManorBattleMgr.ActOpen(
                        stActCfgData);
                }
                break;
            default:
                break;
            }
        }
        
        //活动关闭
        if (stActCfgData.IsAutoClose() || stActCfgData.IsForceClose())
        {
            switch (stActCfgData.GetResID())
            {
            case ACT_ID_WORLD_BOSS:
                {
                    CMainCtrl::m_pstMain->m_stWorldBossMgr.ActClose(
                        stActCfgData);
                }
                break;
            case ACT_ID_GRAN_BOSS://格兰学院BOSS活动ID
            case ACT_ID_SLEN_BOSS://斯林学院BOSS活动ID
            case ACT_ID_RAVAN_BOSS://拉文学院BOSS活动ID
            case ACT_ID_HUFF_BOSS://霍奇学院BOSS活动ID
                {
                    CMainCtrl::m_pstMain->m_stAcademyBossMgr.ActClose(
                        stActCfgData);
                }
                break;
            case ACT_ID_CLAN_BATTLE:
                {
                    CMainCtrl::m_pstMain->m_stClanBattleMgr.SetEnd();
                }
                break;
            case ACT_ID_ENEMY_ATK_CITY:
                {
                    CMainCtrl::m_pstMain->m_stEnemyAtkCityMgr.SetClose();
                }
                break;
            case ACT_ID_FIGHT_END:
                {
                    CMainCtrl::m_pstMain->m_stFightEndMgr.ActClose(
                        stActCfgData);
                }
                break;
            case ACT_ID_MANOR_BATTLE:
                {
                    CMainCtrl::m_pstMain->m_stManorBattleMgr.ActClose(
                        stActCfgData);
                }
                break;
            default:
                break;
            }
        }
    }

    for (int i = 0; i < GetUpdateTimeSize(); ++i)
    {
        //定时更新类活动更新时候的处理逻辑
        switch (GetUpdateTime(i))
        {
        case ACT_UPDATE_TIME_0_00:
            {
                CMainCtrl::m_pstMain->m_stDaySignMgr.NotifyAllOnlineUsers(); //每日签到
                CMainCtrl::m_pstMain->m_stDayWishMgr.NotifyAllOnlineUsers(); //每日许愿
                CMainCtrl::m_pstMain->m_stLoginRewardMgr.NotifyAllOnlineUsers(); //登录奖励
            }
            break;
        case ACT_UPDATE_TIME_23_00:
            {
                //星门充能更新时候除了下发活动列表通知用户可以再次参加活动外
                //还需要下发家族大厅的在线角色以刷新新的一天可以使用的充能次数
                CMainCtrl::m_pstMain->m_stMagicDoorMgr.NotifyAllClanUsers(); //星门充能
            }
            break;
        default:
            break;
        }
    }

    //有活动的状态发生改变, 通知所有玩家
    if (GetNotifyActSize() > 0 || GetUpdateTimeSize() > 0) 
    {
        NotifyActListToAll();
    }
}

void CActMgr::DealActTips()
{
    MsgTips stTips;
    for (int i = 0; i < GetNotifyTipSize(); ++i)
    {
        stTips.set_type(GetNotifyTip(i));
        CMainCtrl::m_pstMain->SendOnlineTips(stTips);
        CMainCtrl::m_pstMain->FlushSendCache();
    }
}

void CActMgr::DealActTimer()
{
    if (GetActTimerSize() <= 0)
    {
        return;
    }

    int iType = 0;
    for (int i = 0; i < GetActTimerSize(); )//不要递增放在逻辑里面
    {
        CActTimer& stActTimer = GetActTimer(i);
        if (stActTimer.GetDelTime() <= 0)
        {
            _astActTimer.DelOneItem(i);
            continue;
        }

        iType = stActTimer.GetType();
        if (iType != CActTimer::ACT_TIMER_MAGIC_DOOR_CLOSE)
        {
            _astActTimer.DelOneItem(i);
            continue;
        }

        if (CMainCtrl::m_pstMain->m_iNow < stActTimer.GetDelTime())
        {
            ++i;
            continue;
        }

        switch (iType)
        {
        case CActTimer::ACT_TIMER_MAGIC_DOOR_CLOSE:
            {
                CMainCtrl::m_pstMain->m_stMagicDoorMgr.TimeUpCloseMagicDoor(
                    stActTimer.GetData());
            }
            break;
        default:
            break;
        }

        //最终只执行一次然后就删除
        _astActTimer.DelOneItem(i);
    }
}

void CActMgr::DealSysStop()
{
    if (_iSysStopTime <= 0)
    {
        return;
    }

#define TIME_INTERVAL_MAX 5
#define TIME_INTERVAL_0 300
#define TIME_INTERVAL_1 60
#define TIME_INTERVAL_2 20
    CTLib::CTArray<int, TIME_INTERVAL_MAX> aiTimeInter;
    aiTimeInter.Clear();
    aiTimeInter.AddOneItem(TIME_INTERVAL_0);
    aiTimeInter.AddOneItem(TIME_INTERVAL_1);
    aiTimeInter.AddOneItem(TIME_INTERVAL_2);

    bool bNotifyTip = false;
    int iRemainTime = _iSysStopTime - CMainCtrl::m_pstMain->m_iNow;

    for (int i = 0; i < aiTimeInter.Size(); ++i)
    {
        if (iRemainTime >= aiTimeInter[i] &&
            (CMainCtrl::m_pstMain->m_iNow >= _iNextNoticeSysStop ||
                0 == _iNextNoticeSysStop))
        {
            bNotifyTip = true;
            _iNextNoticeSysStop = CMainCtrl::m_pstMain->m_iNow + aiTimeInter[i];
            if (iRemainTime < aiTimeInter[i] + aiTimeInter[i] &&
                i + 1 < aiTimeInter.Size())
            {
                _iNextNoticeSysStop =
                    CMainCtrl::m_pstMain->m_iNow + aiTimeInter[i + 1];
            }
            break;
        }
    }

    if (bNotifyTip)
    {
        MsgTips stTips;
        CTSizeString<ROLENAME_LEN> szNameStr;

        stTips.set_type(TIPS_SYSTEM_STOP_NOTICE);
        szNameStr.Set("%d",iRemainTime/60);//剩余分钟
        stTips.add_tip_argument(szNameStr());
        szNameStr.Set("%d",iRemainTime%60);//剩余秒值
        stTips.add_tip_argument(szNameStr());

        if (_szSysStopTime.GetDataLen() > 0)
        {
            stTips.add_tip_argument(_szSysStopTime());
        }

        if (_szSysStartTime.GetDataLen() > 0)
        {
            stTips.add_tip_argument(_szSysStartTime());
        }

        CMainCtrl::m_pstMain->SendOnlineTips(stTips);
        CMainCtrl::m_pstMain->FlushSendCache();
    }

    if (iRemainTime <= 0)
    {
        //创建标识文件
        FILE* fp = fopen("mainsvr_sysstop.log", "wt+");
        if (fp)
        {
            fprintf(fp, "%d\n", CMainCtrl::m_pstMain->m_iNow);
            fclose(fp);
        }
        else
        {
            CT_ERROR(("Fopen mainsvr system stop log error!"));
        }

        ClearSystemStopTime();
        CMainCtrl::m_pstMain->s_bExit = true;
        CMainCtrl::m_pstMain->SetOfflineAllPlayer();
    }
}

void CActMgr::DealSystemNotice()
{
    MsgTips stTips;
    for (int i = 0; i < GetSysNoticeSize(); ++i)
    {
        stTips.Clear();
        stTips.set_type(GetSysNotice(i));
        CMainCtrl::m_pstMain->SendOnlineTips(stTips);
    }

    CMainCtrl::m_pstMain->FlushSendCache();
}

int CActMgr::GMDealAct(MsgReqGMPlayer& stReq, MsgAnsGMPlayer& stAns)
{
    return _stActCfg.GMDealAct(stReq, stAns);
}

int CActMgr::GMDealSystemNotice(MsgReqGMPlayer& stReq, MsgAnsGMPlayer& stAns)
{
    return _stSystemNoticeCfg.GMDealSystemNotice(stReq, stAns);
}

void CActMgr::GetSplendidActTime(const char* szTime, int& iTime, int iBaseTime)
{
    CTSizeString<1024> szTmp;
    iTime = 0;

    //开始时间
    szTmp.Set("%s", szTime);

    if (szTmp.GetDataLen() == 0)
    {
        iTime = CTTimeUtils::GetDayBeginSec(iBaseTime);
        return;
    }
    
    if (szTmp[0] == '+') //相对开服的时间
    {
        int iDays = atoi(szTmp());

        if (iDays < 0)
        {
            iDays = 0;
        }

        iTime = CTTimeUtils::GetDayBeginSec(iBaseTime)
                    + 86400 * iDays;
    }
    else
    {
        string s(szTime);
        CTTime stTime(s);

        iTime = (int)stTime.GetTime();
    }

    if (iTime < 0)
    {
        iTime = 0;
    }
}

bool CActMgr::IsSplendidActValid(int iActID)
{
    int iRet = 0;
    int iNowTime = CMainCtrl::m_pstMain->m_iNow;

    CSplendidActConfigData stConfigData;
    iRet = _stSplendidActConfig.GetConfig(iActID, stConfigData);
    if (iRet)
    {
        CT_ERROR(("get splendid act(%d) config error(%d)", iActID, iRet));
        return false;
    }

    if (iNowTime > stConfigData._iEndTime)
    {
        return false;
    }

    return (iNowTime >= stConfigData._iBeginTime);
}

bool CActMgr::IsSplendidActValid(CSplendidAct& stActData, unsigned int uiGID, int iActID)
{
    int iRet = 0;
    int iNowTime = CMainCtrl::m_pstMain->m_iNow;

    CSplendidActConfigData stConfigData;
    iRet = _stSplendidActConfig.GetConfig(iActID, stConfigData);
    if (iRet)
    {
        CT_WARNING((""));
        return false;
    }

    if (iNowTime > stConfigData._iEndTime)
    {
        return false;
    }

    if (stConfigData._iParentActID != 0
        && stActData.HasFinished(stConfigData._iParentActID))    //有前置任务
    {
        return !stActData.HasGetBonus(iActID);
    }
    else
    {
        return (iNowTime >= stConfigData._iBeginTime);
    }
}

void CActMgr::TriggerCrystalCombine(CSplendidAct& stActData, unsigned int uiGID, unsigned short usCombinedCrystalId, short shCount)
{
    CCrystalConfigData stCombindedCrystal;
    int iRet = CMainCtrl::m_pstMain->m_stItemMgr.GetCrystalConfig(usCombinedCrystalId, stCombindedCrystal);
    if (iRet)
    {
        return ;
    }    

    unsigned char ucCryLevel = (unsigned char)stCombindedCrystal._usLevel;
    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_7)) //魔晶合成赢幸运活动
    {
        for (int i = 0; i < _stSplendidActConfigDetail._astCryCombineLevels.Size(); ++i)
        {
            if (ucCryLevel == _stSplendidActConfigDetail._astCryCombineLevels[i])
            {
                while (i >= stActData._astCombineCount.Size())
                {
                    stActData._astCombineCount.AddOneItem(0);
                }
                stActData._astCombineCount[i] += shCount;

                UpdateSplendidActData(uiGID);

                SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_7);
                break;
            }
        }
    }

    //发送跑马灯
    if (ucCryLevel >= 7)
    {    
        MsgTips stTips;
        stTips.set_type(1004);
        stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
        stTips.add_tip_argument(CTStringUtils::IntToString(stCombindedCrystal._usCrystalConfigID));
        CMainCtrl::m_pstMain->SendOnlineTips(stTips);
    }
}

void CActMgr::TriggerLevelUp(CSplendidAct& stActData, unsigned int uiGID, short shNowLevel)
{
    int iRet = 0;

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_1)) //升到40级夺豪礼
    {
        CSplendidActConfigData stConfigData;
        iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_1, stConfigData);
        if (iRet)
        {
            CT_WARNING((""));
            return;
        }

        if (shNowLevel >= atoi(stConfigData._szTargets()))
        {
            stActData.SetFinished(SPLENDID_ACT_ID_1);

            UpdateSplendidActData(uiGID);
            SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_1);
        }
    }

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_2)) //升到50级夺豪礼
    {
        CSplendidActConfigData stConfigData;
        iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_2, stConfigData);
        if (iRet)
        {
            CT_WARNING((""));
            return;
        }

        if (shNowLevel >= atoi(stConfigData._szTargets()))
        {
            stActData.SetFinished(SPLENDID_ACT_ID_2);

            UpdateSplendidActData(uiGID);
            SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_2);
        }
    }
}

void CActMgr::TriggerPetLevelUp(CSplendidAct& stActData, unsigned int uiGID, short shNowPetLevel)
{
    int iRet = 0;

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_3)) //3阶宠物养成大礼
    {
        CSplendidActConfigData stConfigData;
        iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_3, stConfigData);
        if (iRet)
        {
            CT_WARNING((""));
            return;
        }

        if (shNowPetLevel >= atoi(stConfigData._szTargets()))
        {
            stActData.SetFinished(SPLENDID_ACT_ID_3);

            UpdateSplendidActData(uiGID);
            SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_3);
        }
    }

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_4)) //4阶宠物养成大礼
    {
        CSplendidActConfigData stConfigData;
        iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_4, stConfigData);
        if (iRet)
        {
            CT_WARNING((""));
            return;
        }

        if (shNowPetLevel >= atoi(stConfigData._szTargets()))
        {
            stActData.SetFinished(SPLENDID_ACT_ID_4);

            UpdateSplendidActData(uiGID);
            SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_4);
        }
    }

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_5)) //5阶宠物养成大礼
    {
        CSplendidActConfigData stConfigData;
        iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_5, stConfigData);
        if (iRet)
        {
            CT_WARNING((""));
            return;
        }

        if (shNowPetLevel >= atoi(stConfigData._szTargets()))
        {
            stActData.SetFinished(SPLENDID_ACT_ID_5);

            UpdateSplendidActData(uiGID);
            SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_5);
        }
    }
}

void CActMgr::TriggerGetPartner(CSplendidAct& stActData, unsigned int uiGID, int iPartnerID)
{
    int iRet = 0;

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_6)) //招募湖中仙女
    {
        CSplendidActConfigData stConfigData;
        iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_6, stConfigData);
        if (iRet)
        {
            CT_WARNING((""));
            return;
        }

        if (iPartnerID == atoi(stConfigData._szTargets()))
        {
            stActData.SetFinished(SPLENDID_ACT_ID_6);

            UpdateSplendidActData(uiGID);
            SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_6);
        }
    }
}

void CActMgr::TriggerEacKillEnemy(CSplendidAct& stActData, unsigned int uiGID)
{
    int iRet = 0;

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_9)) 
    {
        CSplendidActConfigData stConfigData;
        iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_9, stConfigData);
        if (iRet)
        {
            CT_WARNING((""));
            return;
        }

        stActData._iEnemyAtkCityKillEnemyCount++;

        UpdateSplendidActData(uiGID);
        SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_9);
    }
}

void CActMgr::TriggerBuyGoods(CSplendidAct& stActData, unsigned int uiGID, unsigned int uiGoodsID, int iCount, int iUseQCent, int iTotalPay)
{
    int iPayGoldCount = 0;
    switch (uiGoodsID)
    {
    case 25:
        iPayGoldCount += 100 * iCount;
        break;
    case 26:
        iPayGoldCount += 500 * iCount;
        break;
    case 27:
        iPayGoldCount += 1000 * iCount;
        break;
    case 28:
        iPayGoldCount += 5000 * iCount;
        break;
    case 86:
        iPayGoldCount += 10 * iCount;
        break;
    case 91:
        iPayGoldCount += iCount;
        break;
    default:
        break;
    }

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_10)) //充值送魔晶活动
    {
        int iIndex = -1;
        for (int i = 0; i < _stSplendidActConfigDetail._astBuyGoldConfigID.Size(); ++i)
        {
            if (_stSplendidActConfigDetail._astBuyGoldConfigID[i] == (int)uiGoodsID)
            {
                iIndex = i;
                break;
            }
        }

        if (iIndex >= 0)
        {
            while (iIndex >= stActData._astBuyGoldCount.Size())
            {
                stActData._astBuyGoldCount.AddOneItem(0);
            }

            if (stActData._astBuyGoldCount[iIndex] > 30000) //保护一下数据
            {
                return;
            }

            stActData._astBuyGoldCount[iIndex] += (short)iCount;

            UpdateSplendidActData(uiGID);
            SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_10);
        }
    }

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_12)) //消费排行
    {
        //累计消费数量
        stActData._iPayRankUseQCent += iPayGoldCount * 10;
        UpdateSplendidActData(uiGID);

        SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_12);
    }

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_16)) //感恩节活动
    {
        if (iPayGoldCount > 0)
        {
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_16);

            stActData._iGanEnPayGoldCount += iPayGoldCount;
            UpdateSplendidActData(uiGID);

            SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_16);
        }
    }

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_18)) //双蛋活动
    {
        unsigned short usShoesNum = (unsigned short)((iPayGoldCount / 100) * 2);
        if (iPayGoldCount > 0)
        {
            int iIndex =
                    CMainCtrl::m_pstMain->m_stPlayerDetailEx1InfoHash.HashFind(
                        uiGID);
            if (iIndex >= 0)
            {
                CPlayerDetailInfoEx1& stPlayerDetailEx1 =
                    CMainCtrl::m_pstMain->m_stPlayerDetailEx1InfoHash[iIndex];
            
                stPlayerDetailEx1._stSplendidActEx1._iSDChargeGold += iPayGoldCount;

                do
                {
                    if (stPlayerDetailEx1._stSplendidActEx1._iSDChargeGold < 5000)
                    {
                        break;
                    }

                    CSDChargeUnit stUnit;
                    stUnit._uiGID = uiGID;
                    stUnit._iGold =
                        stPlayerDetailEx1._stSplendidActEx1._iSDChargeGold;

                    CZoneData& stZoneData =
                        CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;

                    stZoneData._astSDCharge.Update(stUnit);
                
                    CMainCtrl::m_pstMain->m_stRewardBackMgr.UpdateZoneDataToDB();

                }while(0);

                if (usShoesNum > 0)
                {
                    stPlayerDetailEx1._stSplendidActEx1._usSDGreenNum += usShoesNum;
                }

                CMainCtrl::m_pstMain->m_stRewardBackMgr.UpdateDetailEx1ToDB(
                    stPlayerDetailEx1);

                SendSplendidActDetailInfoToFront(stActData, uiGID,
                    SPLENDID_ACT_ID_18);
            }
            else
            {
                CT_ERROR(("no detail ex1 data user(%u) add green shoes(%d)",
                    uiGID, usShoesNum));
            }
        }
    }
}

void CActMgr::TriggerGetItem(CSplendidAct& stActData, unsigned int uiGID, unsigned char ucItemType, int iItemID, int iItemCount)
{
    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_14)) //国庆集卡 双蛋集卡
    {
        if (ucItemType != ITEM_TYPE_MATERIAL)
        {
            return;
        }
        
        if (!(iItemID >= 214 && iItemID <= 221))
        {
            return;
        }

        SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_14);
    }
}

void CActMgr::TriggerGetCard(CSplendidAct& stActData, unsigned int uiGID, unsigned char ucCardType, unsigned short usCardConfigID, int iCardCount)
{
    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_15)) //金秋猎奇
    {
        if (ucCardType == CARD_TYPE_GOLD_CARD)
        {
            stActData._iHasGetGoldCardCount += iCardCount;
            
            //更新排名
            CGoldCardAct stRankData;
            stRankData.uiGID = uiGID;
            stRankData.iGoldCardCount = stActData._iHasGetGoldCardCount;
            int iOldRank = 0;
            int iNewRank = 0;

            //更新排名
            CZoneData& stZoneData = CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;
            stZoneData._astGoldCardAct.Update(stRankData, iOldRank, iNewRank);

            if (iNewRank >= 0)
            {
                //更新大区信息
                CVarObjectKey stKey;
                stKey.m_chDataType = DT_ZONE_DATA;
                stKey.m_u64ID = stZoneData._uiZoneID;
                CMainCtrl::m_pstMain->UpdateData(stKey, stZoneData, VOP_UPDATE);
            }

            //返回数据
            UpdateSplendidActData(uiGID);
            SendSplendidActDetailInfoToFront(stActData, uiGID, SPLENDID_ACT_ID_15);
        }
        
    }
}

void CActMgr::TriggerSubMoney(unsigned int uiGID, int iGold, int iSilver)
{
    int iRet = 0;
    CSplendidActConfigData stConfigData;
    do //采用此结构 方便以后添加其他模块
    {
        iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_20, stConfigData);
        if (iRet)
        {
            CT_ERROR(("get splendid act(%d) config error(%d)", SPLENDID_ACT_ID_20, iRet));
            break;
        }
        if (stConfigData._iBeginTime <= 0 || stConfigData._iEndTime <= stConfigData._iBeginTime)
        {
            CT_ERROR(("splendid act(%d) config begin(%d) end(%d) time error", SPLENDID_ACT_ID_20,
                stConfigData._iBeginTime, stConfigData._iEndTime));
            break;
        }
        if (CMainCtrl::m_pstMain->m_iNow > stConfigData._iEndTime)
        {
            break;
        }
        if (iGold < 0){iGold = 0;}
        if (iSilver < 0){iSilver = 0;}
        if (iGold <= 0 && iSilver <= 0)
        {
            break;
        }

        int iOffsetSec = CTTimeUtils::GetDayBeginSec(CMainCtrl::m_pstMain->m_iNow) -
                CTTimeUtils::GetDayBeginSec(stConfigData._iBeginTime);
        int iDayIndex = iOffsetSec / 86400;
        if (iDayIndex < 0 || iDayIndex >= MAX_SPLENDID_RED_PACKET_ACT_DAY_COUNT ||
            iDayIndex >= MAX_SPLENDID_RED_PACKET_DB_DAY_COUNT)
        {
            CT_ERROR(("splendid act(%d) begin(%d) now(%d) day index(%d) error", SPLENDID_ACT_ID_20,
                stConfigData._iBeginTime, CMainCtrl::m_pstMain->m_iNow, iDayIndex));
            break;
        }

        CCmdInnerActTitle* pstCmd = (CCmdInnerActTitle*)CT_CMDFACTORY->CreateCmd(ID_MAIN_INNER_ACT_TITLE);
        if (!pstCmd){CT_ERROR(("create CCmdInnerActTitle error %u",uiGID));break;}
        
        pstCmd->pstMainCtrl = CMainCtrl::m_pstMain;
        pstCmd->_uiGID = uiGID;
        pstCmd->_iSubCmd = CActMgr::CMD_ACT_OPT_SUB_RED_PACKET_UPDATE;
        pstCmd->_iIndex = iDayIndex;
        pstCmd->_iAuxData1 = iGold;
        pstCmd->_iAuxData2 = iSilver;

        pstCmd->Do(NULL);

    }while(0);
}

void CActMgr::SplendidActSecTick(int iNowTime)
{
    int iRet = 0;
    int iLastUpdateTimeTmp = 0;
    static int iLastCheckTime = 0;

    iLastUpdateTimeTmp = iLastCheckTime;
    if (iLastCheckTime == iNowTime)
    {
        return; //1秒只check 1次
    }
    iLastCheckTime = iNowTime;

    CSplendidActConfigData stConfigData;

    CZoneData& stZoneData =
        CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;

    //双蛋活动
    iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_18, stConfigData);
    if (!iRet
        && iLastUpdateTimeTmp < stConfigData._iEndTime
        && iNowTime >= stConfigData._iEndTime
        && stZoneData._astSDCharge.Size() > 0)
    {
        unsigned int uiGID = stZoneData._astSDCharge[0]._uiGID;

        CDropItem stDropItem;
        CDropItemData stDropItemData;

        stDropItemData._ucItemType = ITEM_TYPE_FASHION;
        stDropItemData._usItemConfigID = 4;
        stDropItemData._iItemCount = 1;
        stDropItem.Drop(stDropItemData);

        stDropItem.SetOssModule(OSS_MODULE_SPDACT);
        iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
        if (iRet)
        {
            CT_ERROR(("SD Act Role(%u) get first rank item (%d %d) error(%d)",
                uiGID, stDropItemData._ucItemType, stDropItemData._usItemConfigID, iRet));
        }
            
        MsgTips stTips;
        stTips.set_type(3031);
        stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
        stDropItem.GetPBMsg(uiGID, *(stTips.mutable_bonus()));
        CMainCtrl::m_pstMain->SendOnlineTips(stTips);
                
        int iIndex = CMainCtrl::m_pstMain->m_stClanMgr.GetClanIndex(uiGID);
        if (iIndex >= 0)
        {
            CClanEntry& stClanEntry =
                CMainCtrl::m_pstMain->m_stClanMgr._stClanEntryHash[iIndex];

            for (int i = 0; i < stClanEntry._astClanMember.Size(); i++)
            {
                CMainCtrl::m_pstMain->m_stItemMgr.DropBonus(OSS_MODULE_SPDACT,
                    stClanEntry._astClanMember[i]._uiGid, 615, 1);
            }
        }
    }

    //家族排名活动
    iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_8, stConfigData);
    if (iRet)
    {
        CT_WARNING((""));
        return;
    }

    if (stConfigData._iEndTime == iNowTime)
    {
        //进行家族排名奖励
        CMainCtrl::m_pstMain->m_stClanMgr.SortClanRank();

        //记录奖励标志
        CCmdSplendidActClanRank* pstCmd = (CCmdSplendidActClanRank*)CT_CMDFACTORY->CreateCmd(ID_MAIN_INNER_SPLENDID_ACT_CLAN_RANK);
        if (!pstCmd)
        {
            CT_WARNING(("create CCmdSplendidActClanRank error"));
            return;
        }

        pstCmd->pstMainCtrl = CMainCtrl::m_pstMain;

        //获取奖励名单
        CClanMgr& stClanMgr = CMainCtrl::m_pstMain->m_stClanMgr;
        for (int i = 0; i < _stSplendidActConfigDetail._iClanRankCount && i < stClanMgr._astClanRank.Size(); ++i)
        {
            int iClanIndex = stClanMgr._astClanRank[i];
            if (!stClanMgr.IsValidIndex(iClanIndex))
            {
                CT_WARNING(("%d", iClanIndex));
                continue;
            }
               
            CClanEntry& stClanEntry =  CMainCtrl::m_pstMain->m_stClanMgr.GetClanEntry(iClanIndex);

            int iMasterGiftID = _stSplendidActConfigDetail._astClanMasterBonus[i];
            int iMemberGiftID = _stSplendidActConfigDetail._astClanMemberBonus[i];

            //族长奖励
            unsigned int uiClanLeader = 0;
            iRet = stClanEntry.GetClanLeader(uiClanLeader);
            if (iRet)
            {
                CT_WARNING(("%u", stClanEntry._uiClanId));
                continue;
            }
            
            pstCmd->_auiBonusGID.AddOneItem(uiClanLeader);
            pstCmd->_aiBonusGiftID.AddOneItem(iMasterGiftID);

            //成员奖励
            for (int j = 0; j < stClanEntry._astClanMember.Size(); ++j)
            {
                if (stClanEntry._astClanMember[j]._uiGid == uiClanLeader) //排除族长
                {
                    continue;
                }

                pstCmd->_auiBonusGID.AddOneItem(stClanEntry._astClanMember[j]._uiGid);
                pstCmd->_aiBonusGiftID.AddOneItem(iMemberGiftID);
            }
        }
        
        pstCmd->Do(NULL);

        //跑马灯
        MsgTips stTips;
        stTips.set_type(1054);
        for (int i = 0; i < 3 && i < stClanMgr._astClanRank.Size(); ++i)
        {
            int iClanIndex = stClanMgr._astClanRank[i];
            if (!stClanMgr.IsValidIndex(iClanIndex))
            {
                CT_WARNING(("%d", iClanIndex));
                continue;
            }

            CClanEntry& stClanEntry =  CMainCtrl::m_pstMain->m_stClanMgr.GetClanEntry(iClanIndex);
            
            if (i == 0)
            {
                //获取族长
                unsigned int uiClanLeader = 0;
                iRet = stClanEntry.GetClanLeader(uiClanLeader);
                if (iRet)
                {
                    CT_WARNING(("%u", stClanEntry._uiClanId));
                    continue;
                }

                stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiClanLeader));
            }

            CTSizeString<CLAN_NAME_STRING_SIZE> szClanName;
            CMainCtrl::m_pstMain->m_stClanMgr.GetClanName(stClanEntry._uiClanId, szClanName);
            stTips.add_tip_argument(szClanName());
            
        }
        CMainCtrl::m_pstMain->SendOnlineTips(stTips);
    }

    //金秋猎金
    iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_15, stConfigData);
    if (iRet)
    {
        CT_WARNING((""));
        return;
    }

    if (stConfigData._iEndTime == iNowTime)
    {
        //记录奖励标志
        CCmdSplendidActGoldCard* pstCmd = (CCmdSplendidActGoldCard*)CT_CMDFACTORY->CreateCmd(ID_MAIN_INNER_SPLENDID_GOLD_CARD);
        if (!pstCmd)
        {
            CT_WARNING(("create CCmdSplendidActGoldCard error"));
            return;
        }

        pstCmd->pstMainCtrl = CMainCtrl::m_pstMain;
        pstCmd->Do(NULL);
    }

    //感恩节大奖初始化
    CTTime stTimeTmp(iNowTime);
    if (iNowTime == CTTimeUtils::GetDayBeginSec(iNowTime)
        && stTimeTmp.GetDayOfWeek() == 1)
    {
        CZoneData& stZoneData = CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;
        stZoneData._ucHasSendGanEnBigGift = 0;

        CVarObjectKey stKey;
        stKey.m_chDataType = DT_ZONE_DATA;
        stKey.m_u64ID = stZoneData._uiZoneID;
        CMainCtrl::m_pstMain->UpdateData(stKey, stZoneData, VOP_UPDATE);
    }
}

void CActMgr::UpdateSplendidActData(unsigned int uiGID)
{
    int iIndex = CMainCtrl::m_pstMain->m_stPlayerDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_WARNING(("%u", uiGID));
        return;
    }

    CPlayerDetailInfo& stPlayerDetailInfo = CMainCtrl::m_pstMain->m_stPlayerDetailInfoHash[iIndex];

    //保存数据
    CVarObjectKey stKey;
    stKey.m_chDataType = DT_PLAYER_DETAIL_INFO;
    stKey.m_u64ID = stPlayerDetailInfo._uiGID;
    CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerDetailInfo, VOP_UPDATE);
}

void CActMgr::UpdateSplendidActData(unsigned int uiGID, int iActID)
{
    int iRet = 0;
    int iIndex = 0;

    iIndex = CMainCtrl::m_pstMain->m_stPlayerDetailInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("role(%u) detail info error", uiGID));
        return;
    }

    CPlayerDetailInfo& stPlayerDetail = CMainCtrl::m_pstMain->m_stPlayerDetailInfoHash[iIndex];

    CSplendidActConfigData stConfigData;
    iRet = _stSplendidActConfig.GetConfig(iActID, stConfigData);
    if (iRet)
    {
        CT_ERROR(("role(%u) get splendid act(%d) config error(%d)", uiGID, iActID, iRet));
        return;
    }

    if (stConfigData._iBeginTime <= 0 || stConfigData._iEndTime <= 0)
    {
        CT_ERROR(("role(%u) splendid act(%d) config begin(%d) or end(%d) time",
            uiGID, iActID, stConfigData._iBeginTime, stConfigData._iEndTime));
        return;
    }

    if (CMainCtrl::m_pstMain->m_iNow < stConfigData._iBeginTime ||
        CMainCtrl::m_pstMain->m_iNow >= stConfigData._iEndTime)
    {
        return;
    }

    CZoneData& stZoneData= CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;

    if (SPLENDID_ACT_ID_16 == iActID)
    {
        if (!(stPlayerDetail._stSplendidAct._iGanEnLastOpenTime >= stConfigData._iBeginTime &&
              stPlayerDetail._stSplendidAct._iGanEnLastOpenTime < stConfigData._iEndTime))
        {
            stPlayerDetail._stSplendidAct.ClearGanEnData();
            stPlayerDetail._stSplendidAct._iGanEnLastOpenTime = stConfigData._iBeginTime;
            CMainCtrl::m_pstMain->m_stRewardBackMgr.UpdateDetailToDB(stPlayerDetail);
        }

        if (!(stZoneData._iGanEnLastOpenTime >= stConfigData._iBeginTime &&
              stZoneData._iGanEnLastOpenTime < stConfigData._iEndTime))
        {
            stZoneData.ClearGanEnData();
            stZoneData._iGanEnLastOpenTime = stConfigData._iBeginTime;
            CMainCtrl::m_pstMain->m_stRewardBackMgr.UpdateZoneDataToDB();
        }
    }
    else if (SPLENDID_ACT_ID_11 == iActID)
    {
        if (!(stPlayerDetail._stSplendidAct._iZQLastOpenTime >= stConfigData._iBeginTime &&
              stPlayerDetail._stSplendidAct._iZQLastOpenTime < stConfigData._iEndTime))
        {
            stPlayerDetail._stSplendidAct.ClearZQData();
            stPlayerDetail._stSplendidAct._iZQLastOpenTime = stConfigData._iBeginTime;
            CMainCtrl::m_pstMain->m_stRewardBackMgr.UpdateDetailToDB(stPlayerDetail);
        }
    }
    else if (SPLENDID_ACT_ID_13 == iActID)
    {
        if (!(stPlayerDetail._stSplendidAct._iGQLastOpenTime >= stConfigData._iBeginTime &&
              stPlayerDetail._stSplendidAct._iGQLastOpenTime < stConfigData._iEndTime))
        {
            stPlayerDetail._stSplendidAct.ClearGQData();
            stPlayerDetail._stSplendidAct._iGQLastOpenTime = stConfigData._iBeginTime;
            CMainCtrl::m_pstMain->m_stRewardBackMgr.UpdateDetailToDB(stPlayerDetail);
        }
    }
}

void CActMgr::GetSplendidActListInfo(CSplendidAct& stActData, unsigned int uiGID, MsgAnsSplendidAct& stAns)
{
    int iRet = 0;
#if 0
    //登录触发
    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_13))  //国庆登录
    {
        CSplendidActConfigData stConfigData;
        iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_13, stConfigData);
        if (RET_OK == iRet)
        {
            if (iNowTime > _stSplendidActConfigDetail._iGQLoginBeginTime
                || iNowTime < _stSplendidActConfigDetail._iGQLoginBeginTime + 86400 * MAX_SPLENDID_GQ_LOGIN_DAYS)
            {
                int iPos = (iNowTime - _stSplendidActConfigDetail._iGQLoginBeginTime) / 86400;

                if (!(stActData._ucHasGQHasLogin & (1 << iPos)))
                {
                    stActData._ucHasGQHasLogin |= (1 << iPos);
                    UpdateSplendidActData(uiGID);
                }
            }
        }
    }
#endif

    if (IsSplendidActValid(stActData, uiGID, SPLENDID_ACT_ID_12))
    {
        int iIndex = CMainCtrl::m_pstMain->m_stPlayerBaseInfoHash.HashFind(uiGID);
        if (iIndex >= 0)
        {
            CPlayerBaseInfo& stPlayerBaseInfo = CMainCtrl::m_pstMain->m_stPlayerBaseInfoHash[iIndex];
            if (stPlayerBaseInfo._stVipData._iPayGold * 10> stActData._iPayRankUseQCent)
            {
                //确保登录时有累计消费排名
                TriggerBuyGoods(stActData, uiGID, 0, 0, 0, stPlayerBaseInfo._stVipData._iPayGold);
            }
        }
    }
    
    for (int i = 1; i <= MAX_SPLENDID_ACT_ID; ++i)
    {
        int iActID = i;

        CSplendidActConfigData stConfigData;
        iRet = _stSplendidActConfig.GetConfig(iActID, stConfigData);
        if (iRet)
        {
            CT_WARNING(("%d", iActID));
            continue;
        }

        if (!stConfigData._bIsSplendidAct)
        {
            continue;
        }

        //有后续活动，且已经完成并领取奖励的活动不显示
        if (stConfigData._bHasChildAct && stActData.HasFinished(iActID) && stActData.HasGetBonus(iActID))
        {
            continue;
        }

        //有后续活动，且已经失效并且没有完成的活动不显示
        if (stConfigData._bHasChildAct && !IsSplendidActValid(stActData, uiGID, iActID) && !stActData.HasFinished(iActID))
        {
            continue;
        }

        //有前置活动，且前置任务有效但是未完成的活动不显示
        if (stConfigData._iParentActID != 0 && IsSplendidActValid(stActData, uiGID, stConfigData._iParentActID) && !stActData.HasFinished(stConfigData._iParentActID))
        {
            continue;
        }

        //有前置活动，且前置任务无效，并且当前任务也无效的任务不显示
        if (stConfigData._iParentActID != 0 && !IsSplendidActValid(stActData, uiGID, stConfigData._iParentActID) && !IsSplendidActValid(stActData, uiGID, iActID))
        {
            continue;
        }

        MsgSplendidActInfo* pstMsgSplendidActInfo = stAns.add_act_info();
        
        GetSplendidActListInfo(stActData, uiGID, iActID, stConfigData, *pstMsgSplendidActInfo);
    }
}

void CActMgr::GetSplendidActListInfo(CSplendidAct& stActData, unsigned int uiGID, int iActID, CSplendidActConfigData& stConfigData, MsgSplendidActInfo& stActInfo)
{
    stActInfo.set_act_id(iActID);
    stActInfo.set_begin_time(stConfigData._iBeginTime);
    stActInfo.set_end_time(stConfigData._iEndTime);

    switch (iActID)
    {
    case SPLENDID_ACT_ID_7: //魔晶合成赢幸运
        {
            stActInfo.set_has_bonus(0);
            for (int i = 0; i < _stSplendidActConfigDetail._astCryCombineBonus.Size(); ++i)
            {
                if (stActData._astCombineCount[i] > 0)
                {
                    stActInfo.set_has_bonus(1);
                    break;
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_8: //全服家族排名活动
        {
            stActInfo.set_has_bonus(stActData._iClanRankBonusGiftID != 0 ? 1 : 0);
        }
        break;
    case SPLENDID_ACT_ID_9: //怪物攻城连杀奖励
        {
            stActInfo.set_has_bonus(0);
            for (int i = 0; i < _stSplendidActConfigDetail._astEacTargets.Size(); ++i)
            {
                if (stActData._iEnemyAtkCityKillEnemyCount >= _stSplendidActConfigDetail._astEacTargets[i])
                {
                    if (!(stActData._usEnemyAtkCityGetBonusStat & (1 << i)))
                    {
                        stActInfo.set_has_bonus(1);
                        break;
                    }
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_10:  //充值送魔晶活动
        {
            stActInfo.set_has_bonus(0);
            for (int i = 0; i < stActData._astBuyGoldCount.Size(); ++i)
            {
                if (stActData._astBuyGoldCount[i] > 0)
                {
                    stActInfo.set_has_bonus(1);
                    break;
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_11:    //中秋活动
        {
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_11);

            int iTodayZeroSec = CTTimeUtils::GetDayBeginSec(CMainCtrl::m_pstMain->m_iNow);
            int iBeginZeroSec = CTTimeUtils::GetDayBeginSec(stConfigData._iBeginTime);

            int iDayIndex = (iTodayZeroSec - iBeginZeroSec) / 86400;

            if (CMainCtrl::m_pstMain->m_iNow >= stConfigData._iBeginTime && iDayIndex < MAX_SPLENDID_ZQ_GIFT_COUNT)
            {
                unsigned char ucCharMask = (unsigned char)((unsigned char)0x1 << iDayIndex);
                if (!(stActData._ucHasGetZQGift & ucCharMask))
                {
                    stActInfo.set_has_bonus(1);
                }
            }
            else
            {
                stActInfo.set_has_bonus(0);
            }
        }
        break;
    case SPLENDID_ACT_ID_12: //消费排行
        {
            stActInfo.set_has_bonus(0);
            for (int i = 0; i < MAX_SPLENDID_PAY_RANK_COUNT; ++i)
            {
                if (stActData._iPayRankUseQCent >= _stSplendidActConfigDetail._astPayRankBonusTarget[i] * 10
                    && !(stActData._ucHasGetPayRankGift & 1 << i))
                {
                    stActInfo.set_has_bonus(1);
                    break;
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_13: //国庆登录有奖
        {
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_13);

            int iTodayZeroSec = CTTimeUtils::GetDayBeginSec(CMainCtrl::m_pstMain->m_iNow);
            int iBeginZeroSec = CTTimeUtils::GetDayBeginSec(stConfigData._iBeginTime);

            int iDayIndex = (iTodayZeroSec - iBeginZeroSec) / 86400;

            if (CMainCtrl::m_pstMain->m_iNow >= stConfigData._iBeginTime && iDayIndex < MAX_SPLENDID_GQ_LOGIN_DAYS)
            {
                unsigned char ucCharMask = (unsigned char)((unsigned char)0x1 << iDayIndex);
                if (!(stActData._ucHasGetGQLoginGift & ucCharMask))
                {
                    stActInfo.set_has_bonus(1);
                }
            }
            else
            {
                stActInfo.set_has_bonus(0);
            }
        }
        break;
    case SPLENDID_ACT_ID_14: //国庆集卡
        {
            int iIndex = CMainCtrl::m_pstMain->m_stPlayerOnlineDataHash.HashFind(uiGID);
            if (iIndex < 0)
            {
                stActInfo.set_has_bonus(0);
            }
            else
            {
                CPlayerOnlineData& stPlayerOnlineData = CMainCtrl::m_pstMain->m_stPlayerOnlineDataHash[iIndex];

                for (int i = 0; i < _stSplendidActConfigDetail._astGQGetCardTargets.Size(); ++i)
                {
                    bool bHasItem = true;
                    for (int j = 0; j < _stSplendidActConfigDetail._astGQGetCardTargets[i].Size(); ++j)
                    {
                        if (0 == CMainCtrl::m_pstMain->m_stStorageMgr.GetItemCount(stPlayerOnlineData._stUserStorage, ITEM_TYPE_MATERIAL, _stSplendidActConfigDetail._astGQGetCardTargets[i][j]))
                        {
                            bHasItem = false;
                            break;
                        }
                    }

                    if (bHasItem)
                    {
                        stActInfo.set_has_bonus(1);
                        break;
                    }
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_15 : //金秋猎金
        {
            stActInfo.set_has_bonus(stActData._ucGoldCardClanBonusCount != 0 || stActData._ucGoldCardRankBonusCount != 0);
        }
        break;
    case SPLENDID_ACT_ID_16: //感恩节活动
        {
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_16);

            int iCanGetCount = (stActData._iGanEnPayGoldCount - 
                                _stSplendidActConfigDetail._iGanEnSendHammerByGold 
                                * stActData._iGanEnHasGetHammerCount / 2) / 
                                _stSplendidActConfigDetail._iGanEnSendHammerByGold * 2;
            if (iCanGetCount > 0
                || (stActData._iGanEnPayGoldCount > _stSplendidActConfigDetail._iGanEnSendMountByGold
                    && stActData._ucGanEnHasGetMount == 0))
            {
                stActInfo.set_has_bonus(1);
            }
            else
            {
                stActInfo.set_has_bonus(0);
            }
            
        }
        break;
    default:
        {
            stActInfo.set_has_bonus((stActData.HasFinished(iActID) && !stActData.HasGetBonus(iActID)) ? 1 : 0);
        }
        break;
    }
}

int CActMgr::GetSplendidActDetailInfo(CSplendidAct& stActData, unsigned int uiGID, int iActID, MsgAnsSplendidAct& stAns)
{
    CSplendidActConfigData stConfigData;
    int iRet = _stSplendidActConfig.GetConfig(iActID, stConfigData);
    if (iRet)
    {
        CT_WARNING(("%d", iActID));
        return iRet;
    }

    return GetSplendidActDetailInfo(stActData, uiGID, iActID, stConfigData, stAns);
}

int CActMgr::GetSplendidActDetailInfo(CSplendidAct& stActData, unsigned int uiGID, int iActID, CSplendidActConfigData& stConfigData, MsgAnsSplendidAct& stAns)
{
    int iRet = 0;
    int iIndex = 0;

    //获取摘要信息
    GetSplendidActListInfo(stActData, uiGID, iActID, stConfigData, *(stAns.mutable_act_base_info()));

    iIndex = CMainCtrl::m_pstMain->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("no detail ex1 data user(%u)", uiGID));
        return RET_SYSTEM_FAIL;
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 =
        CMainCtrl::m_pstMain->m_stPlayerDetailEx1InfoHash[iIndex];

    CSplendidActEx1& stActEx1Data = stPlayerDetailEx1._stSplendidActEx1;

    //获取详细信息
    switch (iActID)
    {
    case SPLENDID_ACT_ID_1: //升到40级夺豪礼
    case SPLENDID_ACT_ID_2: //升到50级夺豪礼
        {
            short shNowLevel = 0;
            iRet = CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleLevel(uiGID, shNowLevel);
            CHECK_RETURN(iRet);

            stAns.set_now_level(shNowLevel);
            stAns.set_dest_level(atoi(stConfigData._szTargets()));
        }
        break;
    case SPLENDID_ACT_ID_3: //宠物养成大礼
    case SPLENDID_ACT_ID_4:
    case SPLENDID_ACT_ID_5:
        {
            int iIndex = CMainCtrl::m_pstMain->m_stPlayerBaseInfoHash.HashFind(uiGID);
            if (iIndex < 0)
            {
                CT_ERROR(("%u", uiGID));
                return RET_SYS_ERROR;
            }
            CPlayerBaseInfo& stPlayerBaseInfo = CMainCtrl::m_pstMain->m_stPlayerBaseInfoHash[iIndex];

            stAns.set_pet_level(stPlayerBaseInfo._stUserPetData._iPetLevel);
            stAns.set_pet_star(stPlayerBaseInfo._stUserPetData._iPetStar);
            stAns.set_dest_pet_level(atoi(stConfigData._szTargets()));
        }
        break;
    case SPLENDID_ACT_ID_6: //招募湖中仙女
        {
            int iIndex = CMainCtrl::m_pstMain->m_stPlayerDetailInfoHash.HashFind(uiGID);
            if (iIndex < 0)
            {
                CT_ERROR(("%u", uiGID));
                return RET_SYS_ERROR;
            }
            CPlayerDetailInfo& stPlayerDetailInfo = CMainCtrl::m_pstMain->m_stPlayerDetailInfoHash[iIndex];

            stAns.set_now_rep(stPlayerDetailInfo._iReputation);

            iIndex = CMainCtrl::m_pstMain->m_stPartnerMgr.FindPartnerCfg(atoi(stConfigData._szTargets()));
            if (iIndex >= 0)
            {
                CPartnerCfgData& stConfig = CMainCtrl::m_pstMain->m_stPartnerMgr.GetPartnerCfg(iIndex);
                stAns.set_dest_rep(stConfig.GetReq());
            }
        }
        break;
    case SPLENDID_ACT_ID_7: //魔晶合成赢幸运
        {
            for (int i = 0; i < _stSplendidActConfigDetail._astCryCombineBonus.Size(); ++i)
            {
                stAns.add_can_get_cry_bonus(stActData._astCombineCount[i]);
            }
        }
        break;
    case SPLENDID_ACT_ID_8: //全服家族排名活动
        {
            stAns.set_now_clan_rank(CMainCtrl::m_pstMain->m_stClanMgr.GetClanRank(uiGID));
        }
        break;
    case SPLENDID_ACT_ID_9: //怪物攻城连杀奖励
        {
            stAns.set_now_kill_enemy_count(stActData._iEnemyAtkCityKillEnemyCount);
            for (int i = 0; i < _stSplendidActConfigDetail._astEacTargets.Size(); ++i)
            {
                if (stActData._iEnemyAtkCityKillEnemyCount >= _stSplendidActConfigDetail._astEacTargets[i])
                {
                    stAns.add_can_get_eac_bonus((stActData._usEnemyAtkCityGetBonusStat & (1 << i)) ? 2 : 1); // 0: 未达成 1：可领取 2：已领取
                }
                else
                {
                    stAns.add_can_get_eac_bonus(0);
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_10: //充值送魔晶活动
        {
            for (int i = 0; i < stActData._astBuyGoldCount.Size(); ++i)
            {
                stAns.add_buy_gold_config_count(stActData._astBuyGoldCount[i]);
            }
        }
        break;
    case SPLENDID_ACT_ID_11: //中秋活动
        {
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_11);

            int iTodayZeroSec = CTTimeUtils::GetDayBeginSec(CMainCtrl::m_pstMain->m_iNow);
            int iBeginZeroSec = CTTimeUtils::GetDayBeginSec(stConfigData._iBeginTime);

            int iTodayDayIndex = (iTodayZeroSec - iBeginZeroSec) / 86400;

#define MACRO_SPLENDID_ZQ_CAN_GET 0    //可领取
#define MACRO_SPLENDID_ZQ_ALREADY 1    //已领取
#define MACRO_SPLENDID_ZQ_CAN_NOT 2    //不符合领取条件

            unsigned char ucCharMask = 0;
            for (int i = 0; i < MAX_SPLENDID_ZQ_GIFT_COUNT; ++i)
            {
                ucCharMask = (unsigned char)((unsigned char)0x1 << i);
                if (i < iTodayDayIndex)
                {
                    if ((stActData._ucHasGetZQGift & ucCharMask))
                    {
                        stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_ZQ_ALREADY);
                    }
                    else
                    {
                        stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_ZQ_CAN_NOT);
                    }
                }
                else if (i == iTodayDayIndex)
                {
                    if ((stActData._ucHasGetZQGift & ucCharMask))
                    {
                        stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_ZQ_ALREADY);
                    }
                    else
                    {
                        stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_ZQ_CAN_GET);
                    }
                }
                else
                {
                    stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_ZQ_CAN_NOT);
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_12: //消费排行
        {
            stAns.set_pay_rank_now_use_qcent(stActData._iPayRankUseQCent / 10);
            for (int i = 0; i < MAX_SPLENDID_PAY_RANK_COUNT; ++i)
            {
                if (stActData._ucHasGetPayRankGift & (1 << i))
                {
                    stAns.add_pay_rank_get_bonus_stat(2);
                }
                else
                {
                    if (stActData._iPayRankUseQCent >= _stSplendidActConfigDetail._astPayRankBonusTarget[i] * 10)
                    {
                        stAns.add_pay_rank_get_bonus_stat(1);
                    }
                    else
                    {
                        stAns.add_pay_rank_get_bonus_stat(0);
                    }
                }
            }
            
        }
        break;
    case SPLENDID_ACT_ID_13: //国庆登录有奖
        {
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_13);

            int iTodayZeroSec = CTTimeUtils::GetDayBeginSec(CMainCtrl::m_pstMain->m_iNow);
            int iBeginZeroSec = CTTimeUtils::GetDayBeginSec(stConfigData._iBeginTime);

            int iTodayDayIndex = (iTodayZeroSec - iBeginZeroSec) / 86400;

#define MACRO_SPLENDID_GQ_CAN_GET 0    //可领取
#define MACRO_SPLENDID_GQ_ALREADY 1    //已领取
#define MACRO_SPLENDID_GQ_CAN_NOT 2    //不符合领取条件

            unsigned char ucCharMask = 0;
            for (int i = 0; i < MAX_SPLENDID_GQ_LOGIN_DAYS; ++i)
            {
                ucCharMask = (unsigned char)((unsigned char)0x1 << i);
                if (i < iTodayDayIndex)
                {
                    if ((stActData._ucHasGetGQLoginGift & ucCharMask))
                    {
                        stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_GQ_ALREADY);
                    }
                    else
                    {
                        stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_GQ_CAN_NOT);
                    }
                }
                else if (i == iTodayDayIndex)
                {
                    if ((stActData._ucHasGetGQLoginGift & ucCharMask))
                    {
                        stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_GQ_ALREADY);
                    }
                    else
                    {
                        stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_GQ_CAN_GET);
                    }
                }
                else
                {
                    stAns.add_gq_get_bonus_stat(MACRO_SPLENDID_GQ_CAN_NOT);
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_14: //国庆集卡
        {
            int iIndex = CMainCtrl::m_pstMain->m_stPlayerOnlineDataHash.HashFind(uiGID);
            if (iIndex < 0)
            {
                for (int i = 0; i < _stSplendidActConfigDetail._astGQGetCardTargets.Size(); ++i)
                {
                    stAns.add_gq_get_card_stat(0);
                }
            }
            else
            {
                CPlayerOnlineData& stPlayerOnlineData = CMainCtrl::m_pstMain->m_stPlayerOnlineDataHash[iIndex];

                for (int i = 0; i < _stSplendidActConfigDetail._astGQGetCardTargets.Size(); ++i)
                {
                    bool bHasItem = true;
                    for (int j = 0; j < _stSplendidActConfigDetail._astGQGetCardTargets[i].Size(); ++j)
                    {
                        if (0 == CMainCtrl::m_pstMain->m_stStorageMgr.GetItemCount(stPlayerOnlineData._stUserStorage, ITEM_TYPE_MATERIAL, _stSplendidActConfigDetail._astGQGetCardTargets[i][j]))
                        {
                            bHasItem = false;
                            break;
                        }
                    }

                    if (bHasItem)
                    {
                        stAns.add_gq_get_card_stat(1);
                    }
                    else
                    {
                        stAns.add_gq_get_card_stat(0);
                    }
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_15 : //金秋猎金
        {
            stAns.set_gold_card_rank_bonus(stActData._ucGoldCardRankBonusCount > 0 ? 1 : 0);
            stAns.set_gold_card_clan_bonus(stActData._ucGoldCardClanBonusCount > 0 ? 1 : 0);

            //排名
            CZoneData& stZoneData= CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;
            for (int i = 0; i < stZoneData._astGoldCardAct.Size(); ++i)
            {
                unsigned int uiDestGID = stZoneData._astGoldCardAct[i].uiGID;
                int iCardCount = stZoneData._astGoldCardAct[i].iGoldCardCount;
                int iRank = i + 1;

                MsgGoldCardRankData* pstMsgGoldCardRankData = stAns.add_gold_card_rank_info();
                pstMsgGoldCardRankData->set_rank(iRank);
                pstMsgGoldCardRankData->set_gid(uiDestGID);
                pstMsgGoldCardRankData->set_count(iCardCount);
                pstMsgGoldCardRankData->set_role_name(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiDestGID));

                CTSizeString<CLAN_NAME_STRING_SIZE> stClanName;
                int iIndexTmp = CMainCtrl::m_pstMain->m_stPlayerSnsCommInfoHash.HashFind(uiDestGID);
                if (iIndexTmp >= 0)
                {
                    unsigned int uiClanID = CMainCtrl::m_pstMain->m_stPlayerSnsCommInfoHash[iIndexTmp]._uiClanId;  
                    CMainCtrl::m_pstMain->m_stClanMgr.GetClanName(uiClanID, stClanName);
                    
                }
                
                pstMsgGoldCardRankData->set_clan_name(stClanName());
            }
        }
        break;
    case SPLENDID_ACT_ID_16:    //感恩节活动 
        {
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_16);
            stAns.set_hammer_count(stActData._iGanEnHammerCount);
            stAns.set_has_charge_gold_count(stActData._iGanEnPayGoldCount);
            stAns.set_has_get_mount(stActData._ucGanEnHasGetMount);
            stAns.set_has_get_cry(stActData._ucGanEnHasGetCry);
            stAns.set_has_get_hammer_countaa(stActData._iGanEnHasGetHammerCount);

            CZoneData& stZoneData = CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;
            for (int i = stZoneData._aui64GanEnRecorder.Size() - 1; i >= 0; --i)
            {
                uint64 uiData = stZoneData._aui64GanEnRecorder[i];
                if (uiData <= 0)
                {
                    continue;
                }
                MsgGanEnHis* pstMsgGanEnHis = stAns.add_ganen_his();
                pstMsgGanEnHis->set_role_name(
                    CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(
                        CT_UINT64_HIGH(uiData)));
                pstMsgGanEnHis->set_gift_id(CT_UINT64_LOW(uiData));
            }
        }
        break;
    case SPLENDID_ACT_ID_17: //转盘
        {
            unsigned char ucCanGetGift = 0;
            unsigned char ucGetGiftTimes = 0;
            int iNowTime = CMainCtrl::m_pstMain->m_iNow;
            int iLuckyPoint = stActData._stZPLuckyPoint.Get(iNowTime);
            ucGetGiftTimes = stActData._stZPHasGetLuckyBonusTo.Get(iNowTime);

            if (iLuckyPoint >= 2000)
            {
                ucCanGetGift = 6;
            }
            else if (iLuckyPoint >= 1000)
            {
                ucCanGetGift = 5;
            }
            else if (iLuckyPoint >= 500)
            {
                ucCanGetGift = 4;
            }
            else if (iLuckyPoint >= 200)
            {
                ucCanGetGift = 3;
            }
            else if (iLuckyPoint >= 100)
            {
                ucCanGetGift = 2;
            }
            else if (iLuckyPoint >= 30)
            {
                ucCanGetGift = 1;
            }
            
#define MACRO_LUCKY_DIAL_CAN_NOT 0    //未达到领取条件
#define MACRO_LUCKY_DIAL_CAN_GET 1    //可领取
#define MACRO_LUCKY_DIAL_ALREADY 2    //已领取

            for (int i = 0;
                 i < _stSplendidActConfigDetail._astZPGift1.GetCount(); ++i)
            {
                if (i < ucGetGiftTimes)
                {
                    stAns.add_zp_bonus_list(MACRO_LUCKY_DIAL_ALREADY);
                }
                else if (i < ucCanGetGift)
                {
                    stAns.add_zp_bonus_list(MACRO_LUCKY_DIAL_CAN_GET);
                }
                else
                {
                    stAns.add_zp_bonus_list(MACRO_LUCKY_DIAL_CAN_NOT);
                }
            }

            stAns.set_zp_free_times(
                (MAX_SPLENDID_LUCKY_DIAL_FREE_ROLL -
                    stActData._stZPHasFreeOptCount.Get(iNowTime)));

            stAns.set_zp_point(iLuckyPoint);
            stAns.set_zp_has_get_big_bonus(stActData._ucZPHasGetBigBonus);

            CZoneData& stZoneData =
                CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;

            for (int i = stZoneData._aui64ZPRecorder.Size() - 1; i >= 0; --i)
            {
                uint64 uiData = stZoneData._aui64ZPRecorder[i];
                if (uiData <= 0)
                {
                    continue;
                }
                MsgGanEnHis* pstMsgGanEnHis = stAns.add_zp_has_get_his();
                pstMsgGanEnHis->set_role_name(
                    CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(
                        CT_UINT64_HIGH(uiData)));
                pstMsgGanEnHis->set_gift_id(CT_UINT64_LOW(uiData));
            }
        }
        break;
    case SPLENDID_ACT_ID_18: //双蛋活动
        {
            MsgSplendidSDInfo* pstMsgSDInfo = stAns.mutable_sd_info();
            if (!pstMsgSDInfo)
            {
                CT_ERROR(("MsgRewardBackInfo Pointer Null!"));
                return RET_SYS_NULL_POINTER;
            }

            pstMsgSDInfo->set_green_num(stActEx1Data._usSDGreenNum);
            pstMsgSDInfo->set_blue_num(stActEx1Data._usSDBlueNum);
            pstMsgSDInfo->set_purple_num(stActEx1Data._usSDPurpleNum);
            pstMsgSDInfo->set_red_num(stActEx1Data._usSDRedNum);

            int iIndex = 0;
            CZoneData& stZoneData =
                CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;
            for (int i = 0; i < stZoneData._astSDRecord.Size(); ++i)
            {
	            MsgSDRecordUnit* pstUnit = pstMsgSDInfo->add_record();
                if (!pstUnit)
                {
                    CT_ERROR(("MsgSDRecordUnit Pointer Null!"));
                    continue;
                }
                MsgGridItemInfo* pstItem = pstUnit->mutable_item();
                if (!pstItem)
                {
                    CT_ERROR(("MsgGridItemInfo Pointer Null!"));
                    continue;
                }

                pstUnit->set_name(
                    CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(
                        stZoneData._astSDRecord[i]._uiGID));

                pstItem->set_item_type(stZoneData._astSDRecord[i]._ucItemType);
                pstItem->set_item_config_id(
                    stZoneData._astSDRecord[i]._usItemConfigID);
                pstItem->set_item_count(stZoneData._astSDRecord[i]._iItemCount);
            }

            for (int i = 0; i < stZoneData._astSDCharge.Size(); ++i)
            {
	            MsgSDRankUnit* pstUnit = pstMsgSDInfo->add_rank();
                if (!pstUnit)
                {
                    CT_ERROR(("MsgSDRankUnit Pointer Null!"));
                    continue;
                }

                pstUnit->set_gid(stZoneData._astSDCharge[i]._uiGID);
                pstUnit->set_gold(stZoneData._astSDCharge[i]._iGold);
                pstUnit->set_role_name(
                    CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(
                        stZoneData._astSDCharge[i]._uiGID));

                iIndex = CMainCtrl::m_pstMain->m_stClanMgr.GetClanIndex(
                    stZoneData._astSDCharge[i]._uiGID);
                if (iIndex >= 0)
                {
                    CClanEntry& stClanEntry =
                        CMainCtrl::m_pstMain->m_stClanMgr._stClanEntryHash[iIndex];
                    pstUnit->set_clan_name(stClanEntry._szName.Get());
                }
            }
        }
        break;
    case SPLENDID_ACT_ID_19: //摇摇乐活动
        {
            MsgSplendidRockInfo* pstMsgRockInfo = stAns.mutable_rock_info();
            if (!pstMsgRockInfo)
            {
                CT_ERROR(("MsgSplendidRockInfo Pointer Null!"));
                return RET_SYS_NULL_POINTER;
            }

            pstMsgRockInfo->set_score(stActEx1Data._iRockScore);

            for (int i = 0; i < _stSplendidActConfigDetail._aiRockRandomInt.Size(); ++i)
            {
                pstMsgRockInfo->add_result(_stSplendidActConfigDetail._aiRockRandomInt[i]);
            }

            for (int i = 0; i < _stSplendidActConfigDetail._aiRockExchangeMask.Size(); ++i)
            {
	            MsgKeyValueUnit* pstUnit = pstMsgRockInfo->add_key_value();
                if (!pstUnit)
                {
                    CT_ERROR(("MsgKeyValueUnit Pointer Null!"));
                    continue;
                }
                pstUnit->set_key(_stSplendidActConfigDetail._aiRockExchangeMask[i]);
                if (i < stActEx1Data._aucRockExchange.Size())
                {
                    pstUnit->set_value(stActEx1Data._aucRockExchange[i]);
                }
                else
                {
                    pstUnit->set_value(0);
                }
            }
            
            CZoneData& stZoneData =
                CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;
            for (int i = 0; i < stZoneData._astRockRecord.Size(); ++i)
            {
	            MsgSDRecordUnit* pstUnit = pstMsgRockInfo->add_record();
                if (!pstUnit)
                {
                    CT_ERROR(("MsgSDRecordUnit Pointer Null!"));
                    continue;
                }
                MsgGridItemInfo* pstItem = pstUnit->mutable_item();
                if (!pstItem)
                {
                    CT_ERROR(("MsgGridItemInfo Pointer Null!"));
                    continue;
                }

                pstUnit->set_name(
                    CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(
                        stZoneData._astRockRecord[i]._uiGID));

                pstItem->set_item_type(stZoneData._astRockRecord[i]._ucItemType);
                pstItem->set_item_config_id(
                    stZoneData._astRockRecord[i]._usItemConfigID);
                pstItem->set_item_count(stZoneData._astRockRecord[i]._iItemCount);
            }
        }
        break;
    case SPLENDID_ACT_ID_20: //领红包活动
        {
            CSplendidActConfigData stConfigData;
            iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_20, stConfigData);
            if (iRet)
            {
                CT_ERROR(("get splendid act(%d) config error(%d)", SPLENDID_ACT_ID_20, iRet));
                return RET_SYS_NULL_POINTER;
            }

            MsgSplendidRedPacketInfo* pstMsgRedPacket = stAns.mutable_redp_info();
            if (!pstMsgRedPacket)
            {
                CT_ERROR(("MsgSplendidRedPacketInfo Pointer Null!"));
                return RET_SYS_NULL_POINTER;
            }

            pstMsgRedPacket->set_gather_time(_stSplendidActConfigDetail._iRedPacketGatherStart);//开始领取时间
            if (stActEx1Data._iRedPacketGatherTime >= _stSplendidActConfigDetail._iRedPacketGatherStart)
            {
                pstMsgRedPacket->set_has_gather(1);//表示已经领取
            }
            else
            {
                pstMsgRedPacket->set_has_gather(0);
            }

            int iTodayZeroSec = CTTimeUtils::GetDayBeginSec(CMainCtrl::m_pstMain->m_iNow);
            int iBeginZeroSec = CTTimeUtils::GetDayBeginSec(stConfigData._iBeginTime);

            int iDayIndex = (iTodayZeroSec - iBeginZeroSec) / 86400;

            int64 i64RatioTmp = 0;

            if (CMainCtrl::m_pstMain->m_iNow >= stConfigData._iBeginTime)
            {
                for (int i = 0; i <= iDayIndex && i < MAX_SPLENDID_RED_PACKET_ACT_DAY_COUNT &&
                        i < MAX_SPLENDID_RED_PACKET_DB_DAY_COUNT; ++i)
                { 
	                MsgRedPacketdUnit* pstUnit = pstMsgRedPacket->add_red_packet();
                    if (!pstUnit)
                    {
                        CT_ERROR(("MsgRedPacketdUnit Pointer Null!"));
                        continue;
                    }

                    pstUnit->set_time(iBeginZeroSec + i * 86400); 

                    i64RatioTmp = INT64_1 * stActEx1Data._astRedPacket[i]._iGold * MAX_SPLENDID_RED_PACKET_BACK_RATIO;
                    i64RatioTmp /= BATTLE_RATE_SKILL_PERCENT;

                    pstUnit->set_gold((int)(i64RatioTmp));

                    i64RatioTmp = INT64_1 * stActEx1Data._astRedPacket[i]._iSilver * MAX_SPLENDID_RED_PACKET_BACK_RATIO;
                    i64RatioTmp /= BATTLE_RATE_SKILL_PERCENT;

                    pstUnit->set_silver((int)(i64RatioTmp));
                }
            }
        }
        break;
    default:
        return RET_SYS_ERROR;
    }

    stAns.set_has_get_bonus(stActData.HasGetBonus(iActID));

    return 0;
}

int CActMgr::GetSplendidActBonus(CSplendidAct& stActData, unsigned int uiGID, int iActID, int iPos, MsgAnsSplendidAct& stAns)
{
    int iRet = 0;

    int iIndex = CMainCtrl::m_pstMain->m_stPlayerOnlineDataHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("%u", uiGID));
        return RET_SYS_ERROR;
    }
    CPlayerOnlineData& stPlayerOnlineData = CMainCtrl::m_pstMain->m_stPlayerOnlineDataHash[iIndex];

    iIndex = CMainCtrl::m_pstMain->m_stPlayerBaseInfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("%u", uiGID));
        return RET_SYS_ERROR;
    }
    CPlayerBaseInfo& stPlayerBaseInfo = CMainCtrl::m_pstMain->m_stPlayerBaseInfoHash[iIndex];

    iIndex = CMainCtrl::m_pstMain->m_stPlayerDetailEx1InfoHash.HashFind(uiGID);
    if (iIndex < 0)
    {
        CT_ERROR(("gid = %u", uiGID));
        return RET_SYS_ERROR;
    }
    CPlayerDetailInfoEx1& stPlayerDetailEx1 =
        CMainCtrl::m_pstMain->m_stPlayerDetailEx1InfoHash[iIndex];

    CSplendidActEx1& stActEx1Data = stPlayerDetailEx1._stSplendidActEx1;

    CSplendidActConfigData stConfigData;
    iRet = _stSplendidActConfig.GetConfig(iActID, stConfigData);
    if (iRet)
    {
        CT_WARNING(("%d", iActID));
        return iRet;
    }

    int iGiftID = 0;

    CDropItem stDropItem;
    stDropItem.SetOssModule(OSS_MODULE_SPDACT);

    switch (iActID)
    {
    case SPLENDID_ACT_ID_7: //魔晶合成赢幸运
        {
            if (iPos >= stActData._astCombineCount.Size())
            {
                return RET_SYS_ERROR;
            }

            if (stActData._astCombineCount[iPos] <= 0)
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            iGiftID = _stSplendidActConfigDetail._astCryCombineBonus[iPos];

            iRet = CMainCtrl::m_pstMain->m_stStorageMgr.OpenGift(stPlayerOnlineData._stUserStorage, iGiftID, uiGID, stDropItem);
            CHECK_RETURN(iRet);

            stActData._astCombineCount[iPos]--;
        }
        break;
    case SPLENDID_ACT_ID_8: //全服家族排名活动
        {
            if (stActData.HasGetBonus(iActID))
            {
                return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
            }

            if (stActData._iClanRankBonusGiftID == 0)
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            iGiftID = stActData._iClanRankBonusGiftID;
            iRet = CMainCtrl::m_pstMain->m_stStorageMgr.OpenGift(stPlayerOnlineData._stUserStorage, iGiftID, uiGID, stDropItem);
            CHECK_RETURN(iRet);

            stActData.SetGetBonus(iActID);
            stActData._iClanRankBonusGiftID = 0;
        }
        break;
    case SPLENDID_ACT_ID_9: //怪物攻城连杀奖励
        {
            if (iPos >= _stSplendidActConfigDetail._astEacTargets.Size())
            {
                CT_ERROR((""));
                return RET_SYS_ERROR;
            }

            if (stActData._usEnemyAtkCityGetBonusStat & (1 << iPos))
            {
                return ERROR_SPLENDID_ACT_HAS_GET_BONUS; 
            }

            if (stActData._iEnemyAtkCityKillEnemyCount <= 0
                || stActData._iEnemyAtkCityKillEnemyCount < _stSplendidActConfigDetail._astEacTargets[iPos])
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            iGiftID = _stSplendidActConfigDetail._astEacBonus[iPos];
            iRet = CMainCtrl::m_pstMain->m_stStorageMgr.OpenGift(stPlayerOnlineData._stUserStorage, iGiftID, uiGID, stDropItem);
            CHECK_RETURN(iRet);

            //设置已经领取
            stActData._usEnemyAtkCityGetBonusStat |= (1 << iPos);
        }
        break;
    case SPLENDID_ACT_ID_10: //充值送魔晶活动
        {
            if (iPos >= _stSplendidActConfigDetail._astBuyGoldConfigID.Size())
            {
                CT_ERROR((""));
                return RET_SYS_ERROR;
            }

            if (stActData._astBuyGoldCount[iPos] <= 0)
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            iGiftID = _stSplendidActConfigDetail._astBuyGoldGBonus[iPos];

            /*
            CDropItemData stDropItemData;
            stDropItemData._usItemConfigID = iGiftID;
            stDropItemData._iItemCount = 1;
            stDropItemData._ucItemType = ITEM_TYPE_GIFT;
            stDropItemData._iData1 = ADD_GIFT_BAG;

            stDropItem.Drop(stDropItemData);
            stDropItem.SetOssModule(OSS_MODULE_SPDACT);

            iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
            CHECK_RETURN(iRet);
            */
            iRet = CMainCtrl::m_pstMain->m_stStorageMgr.OpenGift(stPlayerOnlineData._stUserStorage, iGiftID, uiGID, stDropItem);
            CHECK_RETURN(iRet);
            
            stActData._astBuyGoldCount[iPos]--;
        }
        break;
    case SPLENDID_ACT_ID_11: //中秋活动
        {
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_11);

            if (iPos < 0 || iPos >= MAX_SPLENDID_ZQ_GIFT_COUNT)
            {
                CT_ERROR((""));
                return RET_SYS_ERROR; 
            }

            if (CMainCtrl::m_pstMain->m_iNow < stConfigData._iBeginTime)
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            int iTodayZeroSec = CTTimeUtils::GetDayBeginSec(CMainCtrl::m_pstMain->m_iNow);
            int iBeginZeroSec = CTTimeUtils::GetDayBeginSec(stConfigData._iBeginTime);

            int iTodayDayIndex = (iTodayZeroSec - iBeginZeroSec) / 86400;
            if (iTodayDayIndex != iPos)
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            unsigned char ucCharMask = (unsigned char)((unsigned char)0x1 << iPos);

            if ((stActData._ucHasGetZQGift & ucCharMask))
            {
                return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
            }
            
            iGiftID = _stSplendidActConfigDetail._astZQGiftID[iPos];

            CDropItemData stDropItemData;
            stDropItemData._usItemConfigID = iGiftID;
            stDropItemData._iItemCount = 1;
            stDropItemData._ucItemType = ITEM_TYPE_GIFT;
            stDropItemData._iData1 = ADD_GIFT_BAG;

            stDropItem.Drop(stDropItemData);
            stDropItem.SetOssModule(OSS_MODULE_SPDACT);

            iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
            CHECK_RETURN(iRet);

            stActData._ucHasGetZQGift |= ucCharMask;
        }
        break;
    case SPLENDID_ACT_ID_12: //消费排行
        {
            if (iPos < 0 || iPos >= MAX_SPLENDID_PAY_RANK_COUNT)
            {
                CT_ERROR((""));
                return RET_SYS_ERROR; 
            }

            if (stActData._ucHasGetPayRankGift & (1 << iPos))
            {
                return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
            }

            if (stActData._iPayRankUseQCent < _stSplendidActConfigDetail._astPayRankBonusTarget[iPos] * 10)
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            iGiftID = _stSplendidActConfigDetail._astPayRankGift[iPos];

            CDropItemData stDropItemData;
            stDropItemData._usItemConfigID = iGiftID;
            stDropItemData._iItemCount = 1;
            stDropItemData._ucItemType = ITEM_TYPE_GIFT;
            stDropItemData._iData1 = ADD_GIFT_BAG;

            stDropItem.Drop(stDropItemData);
            stDropItem.SetOssModule(OSS_MODULE_SPDACT);

            iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
            CHECK_RETURN(iRet);

            stActData._ucHasGetPayRankGift |= (1 << iPos);
            
            int iTipsID = 0;

            if (0 == iPos) {iTipsID = TIPS_TOTAL_CHARGE_STAGE_ONE;}     //累计充值跑马灯--任意符石
            else if (1 == iPos) {iTipsID = TIPS_TOTAL_CHARGE_STAGE_TWO;}//累计充值跑马灯--500符石
            else if (2 == iPos) {iTipsID = TIPS_TOTAL_CHARGE_STAGE_THR;}//累计充值跑马灯--2000符石
            else if (3 == iPos) {iTipsID = TIPS_TOTAL_CHARGE_STAGE_FTH;}//累计充值跑马灯--5000符石
            else if (4 == iPos) {iTipsID = TIPS_TOTAL_CHARGE_STAGE_FIF;}//累计充值跑马灯--10000符石
            else if (5 == iPos) {iTipsID = TIPS_TOTAL_CHARGE_STAGE_SIX;}//累计充值跑马灯--20000符石
            else if (6 == iPos) {iTipsID = TIPS_TOTAL_CHARGE_STAGE_SEV;}//累计充值跑马灯--50000符石

            if (iTipsID > 0)
            {
                MsgTips stTips;
                stTips.set_type(iTipsID);
                stTips.add_tip_argument(stPlayerBaseInfo._sRoleName());
                CMainCtrl::m_pstMain->SendOnlineTips(stTips);
            }
        }
        break; 
    case SPLENDID_ACT_ID_13: //国庆登录奖励
        {
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_13);

            if (iPos < 0 || iPos >= MAX_SPLENDID_GQ_LOGIN_DAYS)
            {
                CT_ERROR((""));
                return RET_SYS_ERROR; 
            }

            if (CMainCtrl::m_pstMain->m_iNow < stConfigData._iBeginTime)
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            int iTodayZeroSec = CTTimeUtils::GetDayBeginSec(CMainCtrl::m_pstMain->m_iNow);
            int iBeginZeroSec = CTTimeUtils::GetDayBeginSec(stConfigData._iBeginTime);

            int iTodayDayIndex = (iTodayZeroSec - iBeginZeroSec) / 86400;
            if (iTodayDayIndex != iPos)
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            unsigned char ucCharMask = (unsigned char)((unsigned char)0x1 << iPos);

            if ((stActData._ucHasGetGQLoginGift & ucCharMask))
            {
                return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
            }

            iGiftID = _stSplendidActConfigDetail._astGQLoginGift[iPos];

            CDropItemData stDropItemData;
            stDropItemData._usItemConfigID = iGiftID;
            stDropItemData._iItemCount = 1;
            stDropItemData._ucItemType = ITEM_TYPE_GIFT;
            stDropItemData._iData1 = ADD_GIFT_BAG;

            stDropItem.Drop(stDropItemData);
            stDropItem.SetOssModule(OSS_MODULE_SPDACT);

            iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
            CHECK_RETURN(iRet);

            stActData._ucHasGetGQLoginGift |= ucCharMask;
        }
        break;
    case SPLENDID_ACT_ID_14: //国庆集卡
        {
            if (iPos < 0 || iPos >= MAX_SPLENDID_GQ_GET_CARD_BONUS_COUNT)
            {
                CT_ERROR((""));
                return RET_SYS_ERROR; 
            }

            //获取用户数据
            int iIndex = CMainCtrl::m_pstMain->m_stPlayerOnlineDataHash.HashFind(uiGID);
            if (iIndex < 0)
            {
                CT_ERROR((""));
                return RET_SYS_ERROR;
            }
            CPlayerOnlineData& stPlayerOnlineData = CMainCtrl::m_pstMain->m_stPlayerOnlineDataHash[iIndex];

            iIndex = CMainCtrl::m_pstMain->m_stPlayerDetailInfoHash.HashFind(uiGID);
            if (iIndex < 0)
            {
                CT_ERROR((""));
                return RET_SYS_ERROR;
            }
            CPlayerDetailInfo& stPlayerDetailInfo = CMainCtrl::m_pstMain->m_stPlayerDetailInfoHash[iIndex];

            CSplendidActConfigDetail::T_GQ_GET_CARD_TARGET& stTargets 
                    = _stSplendidActConfigDetail._astGQGetCardTargets[iPos];

            //检查物品
            for (int i = 0; i < stTargets.Size(); ++i)
            {
                if (0 == CMainCtrl::m_pstMain->m_stStorageMgr.GetItemCount(stPlayerOnlineData._stUserStorage, ITEM_TYPE_MATERIAL, stTargets[i]))
                {
                    return ERROR_SPLENDID_ACT_NOT_FINISHED;
                }
            }

            //组装奖励
            iGiftID = _stSplendidActConfigDetail._astGQGetCardGift[iPos];

            CDropItemData stDropItemData;
            stDropItemData._usItemConfigID = iGiftID;
            stDropItemData._iItemCount = 1;
            stDropItemData._ucItemType = ITEM_TYPE_GIFT;
            stDropItemData._iData1 = ADD_GIFT_BAG;

            stDropItem.Drop(stDropItemData);
            stDropItem.SetOssModule(OSS_MODULE_SPDACT);

            if (!stDropItem.HasEnoughSpace(uiGID))
            {
                return ERROR_BAG_WILL_FULL;
            }
            
            //扣除物品
            for (int i = 0; i < stTargets.Size(); ++i)
            {
                iRet = CMainCtrl::m_pstMain->m_stStorageMgr.TakeOutItem(stPlayerOnlineData._stUserStorage, 
                    ITEM_TYPE_MATERIAL, stTargets[i], 1);
                CHECK_RETURN(iRet);
            }

            //发奖
            iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
            CHECK_RETURN(iRet);

            //保存数据
            CMainCtrl::m_pstMain->m_stStorageMgr.GetData(stPlayerOnlineData._stUserStorage, stPlayerDetailInfo._stUserStorage);

            CVarObjectKey stKey;
            stKey.m_chDataType = DT_PLAYER_DETAIL_INFO;
            stKey.m_u64ID = stPlayerDetailInfo._uiGID;
            CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerDetailInfo, VOP_UPDATE);
        }
        break;
    case SPLENDID_ACT_ID_15 : //金秋猎金
        {
            CDropItemData stDropItemData;
            stDropItemData._ucItemType = ITEM_TYPE_GIFT;

            if (iPos == 0) //排名礼包
            {
                if (stActData._ucGoldCardRankBonusCount != 1)
                {
                    return ERROR_SPLENDID_ACT_NOT_FINISHED;
                }

                stDropItemData._usItemConfigID = _stSplendidActConfigDetail._astBuyGoldConfigID[iPos];
                stDropItemData._iItemCount = stActData._ucGoldCardRankBonusCount;
            }
            else if (iPos == 1) //成员礼包
            {
                if (stActData._ucGoldCardClanBonusCount == 0)
                {
                    return ERROR_SPLENDID_ACT_NOT_FINISHED;
                }

                stDropItemData._usItemConfigID = _stSplendidActConfigDetail._astBuyGoldConfigID[iPos];
                stDropItemData._iItemCount = stActData._ucGoldCardClanBonusCount;
            }
            else
            {
                return RET_SYS_ERROR;
            }

            //发奖
            CDropItem stDropItem;
            stDropItem.Drop(stDropItemData);
            stDropItem.SetOssModule(OSS_MODULE_SPDACT);

            if (!stDropItem.HasEnoughSpace(uiGID))
            {
                return ERROR_BAG_WILL_FULL;
            }
            
            //设置状态
            if (iPos == 0)
            {
                stActData._ucGoldCardRankBonusCount = 0;
            }
            else if(iPos == 1)
            {
                stActData._ucGoldCardClanBonusCount = 0;
            }

            //Drop
            iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
            CHECK_RETURN(iRet);
        }
        break;
    case SPLENDID_ACT_ID_16:
        {
            int iBigBonusTipID = 0;
            UpdateSplendidActData(uiGID, SPLENDID_ACT_ID_16);

            switch (iPos)
            {
            case 0: //领锤子
                {
                    int iCanGetCount = (stActData._iGanEnPayGoldCount - 
                                        _stSplendidActConfigDetail._iGanEnSendHammerByGold 
                                        * stActData._iGanEnHasGetHammerCount / 2) / 
                                        _stSplendidActConfigDetail._iGanEnSendHammerByGold * 2;
                    if (iCanGetCount > 0)
                    {
                        stActData._iGanEnHasGetHammerCount += iCanGetCount;
                        stActData._iGanEnHammerCount += iCanGetCount;
                        stAns.set_get_hammer_count(iCanGetCount);
                    } 
                }
                break;
            case 1: //砸蛋
                {
                    int iGiftID = 0;

                    if (stActData._iGanEnHammerCount < 1)
                    {
                        return RET_SYS_ERROR;
                    }
                    
                    CZoneData& stZoneData = CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;
                    
                    if (stActData._iGanEnPayGoldCount < _stSplendidActConfigDetail._iGanEnSendGiftByGold)
                    {
                        iGiftID = _stSplendidActConfigDetail._iGanEnGiftID1;
                    }
                    else
                    {
                        if (stZoneData._ucHasSendGanEnBigGift == 0) //有大奖的
                        {
                            iGiftID = _stSplendidActConfigDetail._iGanEnGiftID3;
                        }
                        else    //没大奖的
                        {
                            iGiftID = _stSplendidActConfigDetail._iGanEnGiftID2;
                        }
                    }

                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.GetGiftItem(iGiftID, uiGID, stDropItem, false);
                    CHECK_RETURN(iRet);

                    //发奖励
                    stDropItem.SetOssModule(OSS_MODULE_EGG);
                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem, true);
                    CHECK_RETURN(iRet);

                    stActData._iGanEnHammerCount--;

                    for (int i = 0; i < stDropItem._astDropItem.Size(); ++i)
                    {
                        CDropItemData& stDropItemData = stDropItem._astDropItem[i];
                        if (stDropItemData._ucItemType == ITEM_TYPE_GIFT) 
                        {
                            switch (stDropItemData._usItemConfigID)
                            {
                            case 654: //中大奖
                                {
                                    stZoneData._ucHasSendGanEnBigGift = 1;

                                    CVarObjectKey stKey;
                                    stKey.m_chDataType = DT_ZONE_DATA;
                                    stKey.m_u64ID = stZoneData._uiZoneID;
                                    CMainCtrl::m_pstMain->UpdateData(stKey, stZoneData, VOP_UPDATE);
                                } //不需要break
                            case 652:
                            case 347:
                            case 656:
                            case 48:
                            case 50:
                            case 505:
                            case 391:
                            case 314:
                            case 595:
                                {
                                    MsgTips stTips;
                                    stTips.set_type(1087);
                                    stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
                                    stTips.add_tip_argument(CTStringUtils::IntToString(stDropItemData._usItemConfigID));
                                    CMainCtrl::m_pstMain->SendOnlineTips(stTips);

                                    //记录历史
                                    uint64 uiData = CT_UINT64_MAKE(uiGID, stDropItemData._usItemConfigID);
                                    if (654 == stDropItemData._usItemConfigID)
                                    {
                                        stZoneData._aui64GanEnRecorder[0] = uiData;
                                    }
                                    else
                                    {
                                        if (stZoneData._aui64GanEnRecorder.Size() == stZoneData._aui64GanEnRecorder.GetCount())
                                        {
                                            if (stZoneData._ucHasSendGanEnBigGift <= 0)
                                            {
                                                stZoneData._aui64GanEnRecorder.ShiftDelOneItem(0);
                                            }
                                            else
                                            {
                                                stZoneData._aui64GanEnRecorder.ShiftDelOneItem(1);
                                            }
                                        }
                                        stZoneData._aui64GanEnRecorder.AddOneItem(uiData);
                                    }

                                    CVarObjectKey stKey;
                                    stKey.m_chDataType = DT_ZONE_DATA;
                                    stKey.m_u64ID = stZoneData._uiZoneID;
                                    CMainCtrl::m_pstMain->UpdateData(stKey, stZoneData, VOP_UPDATE);
                                }
                                break;
                            default:
                                break;
                            }
                        }
                    }
                }
                break;
            case 2: //领坐骑
                {
                    if (stActData._ucGanEnHasGetMount != 0)
                    {
                        return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
                    }

                    if (stActData._iGanEnPayGoldCount < _stSplendidActConfigDetail._iGanEnSendMountByGold)
                    {
                        return ERROR_SPLENDID_ACT_NOT_FINISHED;
                    }
                    
                    CDropItemData stDropItemData;
                    stDropItemData._usItemConfigID = _stSplendidActConfigDetail._iGanEnGiftID4;
                    stDropItemData._iItemCount = 1;
                    stDropItemData._ucItemType = ITEM_TYPE_GIFT;

                    stDropItem.Drop(stDropItemData);
                    stDropItem.SetOssModule(OSS_MODULE_SPDACT);

                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
                    CHECK_RETURN(iRet);

                    stActData._ucGanEnHasGetMount = 1;

                    iBigBonusTipID = 3032;
                }
                break;
            case 3: //领魔晶礼包
                {
                    if (stActData._ucGanEnHasGetCry != 0)
                    {
                        return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
                    }

                    if (stActData._iGanEnPayGoldCount < _stSplendidActConfigDetail._iGanEnSendCryGiftByGold)
                    {
                        return ERROR_SPLENDID_ACT_NOT_FINISHED;
                    }

                    CDropItemData stDropItemData;
                    stDropItemData._usItemConfigID = _stSplendidActConfigDetail._iGanEnGiftID5;
                    stDropItemData._iItemCount = 1;
                    stDropItemData._ucItemType = ITEM_TYPE_GIFT;

                    stDropItem.Drop(stDropItemData);
                    stDropItem.SetOssModule(OSS_MODULE_SPDACT);

                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
                    CHECK_RETURN(iRet);

                    stActData._ucGanEnHasGetCry = 1;
                }
                break;
            case 4: //领金魂罐子
                {
                    if (stActData._ucGanEnHasGetMount != 0)
                    {
                        return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
                    }

                    if (stActData._iGanEnPayGoldCount < _stSplendidActConfigDetail._iGanEnSendMountByGold)
                    {
                        return ERROR_SPLENDID_ACT_NOT_FINISHED;
                    }
                    
                    CDropItemData stDropItemData;
                    stDropItemData._usItemConfigID = _stSplendidActConfigDetail._iGanEnGiftID6;
                    stDropItemData._iItemCount = 1;
                    stDropItemData._ucItemType = ITEM_TYPE_GIFT;

                    stDropItem.Drop(stDropItemData);
                    stDropItem.SetOssModule(OSS_MODULE_SPDACT);

                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
                    CHECK_RETURN(iRet);

                    stActData._ucGanEnHasGetMount = 1;

                    iBigBonusTipID = 3032;
                }
                break;
            default:
                return RET_SYS_ERROR;
            }

            if (iBigBonusTipID > 0)
            {
                MsgTips stTips;
                stTips.set_type(iBigBonusTipID);
                stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
                stDropItem.GetPBMsg(uiGID, *(stTips.mutable_bonus()));
                CMainCtrl::m_pstMain->SendOnlineTips(stTips);
            }
        }
        break;

    case SPLENDID_ACT_ID_17: //转盘
        {
            int iNowTime = CMainCtrl::m_pstMain->m_iNow;
            int iLuckyPoint = stActData._stZPLuckyPoint.Get(iNowTime);
            
            int iFreeRoll = 0;
            int iRollCount = 0;
            int iNeedGold = 0;
            int iNeedSilver = 0;

            switch (iPos)
            {
            case 0: //幸运礼包
                {
                    unsigned char ucCanGetGift = 0;
                    if (iLuckyPoint >= 2000)
                    {
                        ucCanGetGift = 6;
                    }
                    else if (iLuckyPoint >= 1000)
                    {
                        ucCanGetGift = 5;
                    }
                    else if (iLuckyPoint >= 500)
                    {
                        ucCanGetGift = 4;
                    }
                    else if (iLuckyPoint >= 200)
                    {
                        ucCanGetGift = 3;
                    }
                    else if (iLuckyPoint >= 100)
                    {
                        ucCanGetGift = 2;
                    }
                    else if (iLuckyPoint >= 30)
                    {
                        ucCanGetGift = 1;
                    }
                    
                    if (ucCanGetGift == 0)
                    {
                        return RET_SYS_ERROR;
                    }

                    if (stActData._stZPHasGetLuckyBonusTo.Get(iNowTime) >= ucCanGetGift)
                    {
                        return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
                    }
                    
                    ucCanGetGift = stActData._stZPHasGetLuckyBonusTo.Get(iNowTime);
                    int iGiftID = _stSplendidActConfigDetail._astZPGift1[ucCanGetGift];

                    //发奖励
                    CDropItemData stDropItemData;
                    stDropItemData._ucItemType = ITEM_TYPE_GIFT;
                    stDropItemData._usItemConfigID = iGiftID;
                    stDropItemData._iItemCount = 1;
                    stDropItem.Drop(stDropItemData);

                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem, true);
                    CHECK_RETURN(iRet);

                    stActData._stZPHasGetLuckyBonusTo.Add(1, iNowTime);

                    //跑马灯

                    int iMsgID = 0;
                    switch (iGiftID)
                    {
                    case 485:
                        iMsgID = 1089;
                        break;
                    case 607:
                        iMsgID = 1090;
                        break;
                    case 50:
                        iMsgID = 1091;
                        break;
                    case 570:
                        iMsgID = 1092;
                        break;
                    case 571:
                        iMsgID = 1093;
                        break;
                    case 572:
                        iMsgID = 1094;
                        break;
                    case 573:
                        iMsgID = 1095;
                        break;
                    case 574:
                        iMsgID = 1096;
                        break;
                    case 575:
                        iMsgID = 1097;
                        break;
                    default:
                        break;
                    }

                    if (iMsgID > 0)
                    {
                        MsgTips stTips;
                        stTips.set_type(iMsgID);
                        stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
                        CMainCtrl::m_pstMain->SendOnlineTips(stTips);
                    }
                }
                break;
            case 1: 
                {
                    iRollCount = 1;
                    iNeedGold = 10;
                    iNeedSilver = 3000;
                    
                    if (!stPlayerDetailEx1._stActStorage.CheckLuckyDialOneTime())
                    {
                        return ERROR_STORAGE_BAG_IS_FULL;
                    }
                }
                break;
            case 2: 
                {
                    iRollCount = 10;   
                    iNeedGold = 95;
                    iNeedSilver = 30000;

                    if (!stPlayerDetailEx1._stActStorage.CheckLuckyDialTenTime())
                    {
                        return ERROR_STORAGE_BAG_IS_FULL;
                    }
                }
                break;
            default:
                return RET_SYS_ERROR;
            }

            if (iRollCount > 0)
            {
                if (iRollCount == 1 &&
                    stActData._stZPHasFreeOptCount.Get(iNowTime) < MAX_SPLENDID_LUCKY_DIAL_FREE_ROLL) //免费
                {
                    iFreeRoll = 1;
                    iNeedGold = 0;
                    iNeedSilver = 0;
                }

                //检查费用
                if (stPlayerBaseInfo._i64Silver < iNeedSilver)
                {
                    return ERROR_SILVER_LESS;
                }

                if (stPlayerBaseInfo._iGold < iNeedGold)
                {
                    return ERROR_GOLD_LESS;
                }

                int iGiftLevel = 0;
                if (iLuckyPoint <= 29)
                {
                    iGiftLevel = 1;
                }
                else if (iLuckyPoint <= 99)
                {
                    iGiftLevel = 2;
                }
                else if (iLuckyPoint <= 199)
                {
                    iGiftLevel = 3;
                }
                else if (iLuckyPoint <= 499)
                {
                    iGiftLevel = 4;
                }
                else if (iLuckyPoint <= 999)
                {
                    iGiftLevel = 5;
                }
                else if (iLuckyPoint <= 1999)
                {
                    iGiftLevel = 6;
                }
                else if (iLuckyPoint <= 2799)
                {
                    iGiftLevel = 7;
                }
                else
                {
                    iGiftLevel = 8;
                }

                CZoneData& stZoneData = CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;
                if (iRollCount >= 10)
                {
                    stZoneData._aui64ZPRecorder.Clear();
                }
                else if (stZoneData._aui64ZPRecorder.Size() == stZoneData._aui64ZPRecorder.GetCount())
                {

                    stZoneData._aui64ZPRecorder.ShiftDelOneItem(0);
                }
                
                for (int i = 0; i < iRollCount; ++i)
                {
                    int iDestGiftID = (stActData._ucZPHasGetBigBonus == 0 ? _stSplendidActConfigDetail._astZPGift2[iGiftLevel - 1]
                                                                            : _stSplendidActConfigDetail._astZPGift3[iGiftLevel - 1]);

                    CDropItem stDropItemTmp;
                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.GetGiftItem(iDestGiftID, uiGID, stDropItemTmp, false);
                    CHECK_RETURN(iRet);

                    for (int i = 0; stActData._ucZPHasGetBigBonus == 0 && i < stDropItemTmp._astDropItem.Size(); ++i)
                    {
                        if (stDropItemTmp._astDropItem[i]._ucItemType == ITEM_TYPE_GIFT
                            && stDropItemTmp._astDropItem[i]._usItemConfigID == 485)
                        {
                            stActData._ucZPHasGetBigBonus = 1;
                            break;
                        }
                    }

                    //增加礼包
                    for (int i = 0; i < stDropItemTmp._astDropItem.Size(); ++i)
                    {
                        stDropItem.Drop(stDropItemTmp._astDropItem[i]);
                    }
                }

                if (iNeedGold > 0 || iNeedSilver > 0)
                {
                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.SubGold(
                        stPlayerBaseInfo, OSS_MONEY_MODULE_57, iNeedGold);
                    CHECK_RETURN(iRet);

                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.SubSilver(stPlayerBaseInfo, iNeedSilver, 0);
                    CHECK_RETURN(iRet);

                    CMainCtrl::m_pstMain->m_stNotifyMgr.Notify(uiGID,
                        NOTIFY_USER_MONEY);
                }

                //发货
                CMainCtrl::m_pstMain->m_stStorageMgr.AddItemToActStorage(
                    stPlayerDetailEx1, stDropItem,
                    ENM_ACT_STORAGE_LUCKY_DIAL);

                CMainCtrl::m_pstMain->m_stStorageMgr.SendActStorageToFront(
                    stPlayerDetailEx1, ENM_ACT_STORAGE_LUCKY_DIAL);

                //增加幸运值
                stActData._stZPLuckyPoint.Add(iRollCount, iNowTime);

                if (iFreeRoll > 0)
                {
                    stActData._stZPHasFreeOptCount.Add(iFreeRoll, iNowTime);
                }

                //增加记录
                for (int i = 0; i < stDropItem._astDropItem.Size(); ++i)
                {
                    int iGiftID = stDropItem._astDropItem[i]._usItemConfigID;
                    uint64 uiData = CT_UINT64_MAKE(uiGID, iGiftID);

                    if (stZoneData._aui64ZPRecorder.GetCount() == stZoneData._aui64ZPRecorder.Size())
                    {
                        stZoneData._aui64ZPRecorder.ShiftDelOneItem(0);
                    }
                    stZoneData._aui64ZPRecorder.AddOneItem(uiData);

                    //跑马灯
                    int iMsgID = 0;
                    switch (iGiftID)
                    {
                    case 485:
                        iMsgID = 1089;
                        break;
                    case 607:
                        iMsgID = 1090;
                        break;
                    case 50:
                        iMsgID = 1091;
                        break;
                    case 570:
                        iMsgID = 1092;
                        break;
                    case 571:
                        iMsgID = 1093;
                        break;
                    case 572:
                        iMsgID = 1094;
                        break;
                    case 573:
                        iMsgID = 1095;
                        break;
                    case 574:
                        iMsgID = 1096;
                        break;
                    case 575:
                        iMsgID = 1097;
                        break;
                    default:
                        break;
                    }

                    if (iMsgID > 0)
                    {
                        MsgTips stTips;
                        stTips.set_type(iMsgID);
                        stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
                        CMainCtrl::m_pstMain->SendOnlineTips(stTips);
                    }
                }

                //保存数据
                CVarObjectKey stKey;
                stKey.m_chDataType = DT_ZONE_DATA;
                stKey.m_u64ID = stZoneData._uiZoneID;
                CMainCtrl::m_pstMain->UpdateData(stKey, stZoneData, VOP_UPDATE);

                stKey.m_chDataType = DT_PLAYER_BASE_INFO;
                stKey.m_u64ID = stPlayerBaseInfo._uiGID;
                CMainCtrl::m_pstMain->UpdateData(stKey, stPlayerBaseInfo, VOP_UPDATE);
            }
        }
        break;

    case SPLENDID_ACT_ID_18:	//双蛋
        {
            //因为有数值性的奖励 这里必须先判断背包格子
            if (stPlayerOnlineData._stUserStorage.GetBagEmptyGridCount() < 1)
            {
                return ERROR_STORAGE_BAG_IS_FULL;
            }

            int iGiftID = 0;
            int iNowTime = CMainCtrl::m_pstMain->m_iNow;
            CZoneData& stZoneData =
                CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;
            unsigned char ucHasGetBigBonus = 0;
            int iChgGreenShoes = 0;
            int iChgBlueShoes = 0;
            int iChgPurpleShoes = 0;
            int iChgRedShoes = 0;

            switch (iPos) 
            {
                case 0://开启绿色袜子
                    {
                        if (stActEx1Data._usSDGreenNum <= 0)
                        {
                            return ERROR_SPLENDID_ACT_NOT_FINISHED;
                        }

                        if (stActEx1Data._iSDChargeGold >= 20000
                            && stActEx1Data._ucSDGetBigBonus <= 0
                            && (stZoneData._ucSDGetBigBonus <
                                    MAX_SPLENDID_SD_BIG_BONUS_COUNT))
                        {
                            iGiftID = _stSplendidActConfigDetail._astSDGift1[0];
                        }
                        else
                        {
                            iGiftID = _stSplendidActConfigDetail._astSDGift2[0];
                        }

                        --iChgGreenShoes;
                    }
                    break;

                case 1://开启蓝色袜子
                    {
                        if (stActEx1Data._usSDBlueNum <= 0) 	
                        {
                            return ERROR_SPLENDID_ACT_NOT_FINISHED;
                        }
                        if (stActEx1Data._iSDChargeGold >= 20000
                            && stActEx1Data._ucSDGetBigBonus <= 0
                            && (stZoneData._ucSDGetBigBonus <
                                    MAX_SPLENDID_SD_BIG_BONUS_COUNT))
                        {
                            iGiftID = _stSplendidActConfigDetail._astSDGift1[1];
                        }
                        else
                        {
                            iGiftID = _stSplendidActConfigDetail._astSDGift2[1];
                        }

                        --iChgBlueShoes;
                    }
                    break;

                case 2://开启紫色袜子
                    {
                        if (stActEx1Data._usSDPurpleNum <= 0)
                        {
                            return ERROR_SPLENDID_ACT_NOT_FINISHED;
                        }
                        if (stActEx1Data._iSDChargeGold >= 20000
                            && stActEx1Data._ucSDGetBigBonus <= 0
                            && (stZoneData._ucSDGetBigBonus <
                                    MAX_SPLENDID_SD_BIG_BONUS_COUNT))
                        {
                            iGiftID = _stSplendidActConfigDetail._astSDGift1[2];
                        } 
                        else
                        {
                            iGiftID = _stSplendidActConfigDetail._astSDGift2[2];
                        }

                        --iChgPurpleShoes;
                    }
                    break;

                case 3://开启红色袜子
                    {
                        if (stActEx1Data._usSDRedNum <= 0)
                        {
                            return ERROR_SPLENDID_ACT_NOT_FINISHED;
                        }

                        if (stActEx1Data._iSDChargeGold >= 20000
                            && stActEx1Data._ucSDGetBigBonus <= 0
                            && (stZoneData._ucSDGetBigBonus <
                                    MAX_SPLENDID_SD_BIG_BONUS_COUNT))
                        {
                            iGiftID = _stSplendidActConfigDetail._astSDGift1[3];
                        } 
                        else
                        {
                            iGiftID = _stSplendidActConfigDetail._astSDGift2[3];
                        }

                        --iChgRedShoes;
                    }
                    break;

                case 10://双蛋每日登录礼包
                    {
                        if (stActEx1Data._stHasGetSDLoginGift.Get(iNowTime) >= 1) 
                        {
                            return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
                        }

                        CDropItemData stDropItemData;
                        stDropItemData._usItemConfigID = 635;
                        stDropItemData._iItemCount = 1;
                        stDropItemData._ucItemType = ITEM_TYPE_GIFT;
                        stDropItem.Drop(stDropItemData);

                        iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
                        CHECK_RETURN(iRet);

                        stActEx1Data._stHasGetSDLoginGift.Add(1, iNowTime);
                    }
                    break;

                default:
                    break;
            }

            if (iGiftID > 0) 
            {
                CDropItem stDropItemTmp;
                iRet = CMainCtrl::m_pstMain->m_stItemMgr.GetGiftItem(iGiftID, uiGID, stDropItemTmp, false);
                CHECK_RETURN(iRet);

                for (int i = 0; i < stDropItemTmp._astDropItem.Size(); ++i) 
                {
                    if (stDropItemTmp._astDropItem[i]._ucItemType == ITEM_TYPE_GIFT
                        && (stDropItemTmp._astDropItem[i]._usItemConfigID == 619
                            || stDropItemTmp._astDropItem[i]._usItemConfigID == 623))
                    {		
                        ++iChgBlueShoes;
                    }
                    else if (stDropItemTmp._astDropItem[i]._ucItemType == ITEM_TYPE_GIFT	
                        && (stDropItemTmp._astDropItem[i]._usItemConfigID == 620 
                            || stDropItemTmp._astDropItem[i]._usItemConfigID == 624)) 
                    {
                        ++iChgPurpleShoes;
                    }
                    else if (stDropItemTmp._astDropItem[i]._ucItemType == ITEM_TYPE_GIFT
                        && (stDropItemTmp._astDropItem[i]._usItemConfigID == 621
                            || stDropItemTmp._astDropItem[i]._usItemConfigID == 625)) 
                    {
                        ++iChgRedShoes;
                    }
                    else
                    {
                        if (stDropItemTmp._astDropItem[i]._ucItemType == ITEM_TYPE_FASHION
                            && stDropItemTmp._astDropItem[i]._usItemConfigID == 8)
                        {
                            ++ucHasGetBigBonus;
                        }

                        stDropItem.Drop(stDropItemTmp._astDropItem[i]);
                    }
                }

                iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem, true);
                CHECK_RETURN(iRet);

                stActEx1Data._usSDGreenNum += iChgGreenShoes;
                stActEx1Data._usSDBlueNum += iChgBlueShoes;
                stActEx1Data._usSDPurpleNum += iChgPurpleShoes;
                stActEx1Data._usSDRedNum += iChgRedShoes;
                stActEx1Data._ucSDGetBigBonus += ucHasGetBigBonus;
                stZoneData._ucSDGetBigBonus += ucHasGetBigBonus;

                int iTipsID = 0;
                bool bUpdateRecord = false;
                CSDRecordUnit stRecordUnit;

                for (int i = 0; i < stDropItem._astDropItem.Size(); ++i)
                {
                    bUpdateRecord = false;
                    if (stDropItem._astDropItem[i]._ucItemType == ITEM_TYPE_GIFT)
                    {
                        switch (stDropItem._astDropItem[i]._usItemConfigID)
                        {
                        case 514:
                        case 505:
                        case 553:
                        case 50:
                        case 347:
                        case 310:
                        case 633:
                        case 354:
                        case 598:
                            if (iTipsID <= 0)
                            {
                                iTipsID = 3030;
                            }
                            bUpdateRecord = true;
                            break;
                        default:
                            break;
                        }
                    }

                    if (stDropItem._astDropItem[i]._ucItemType == ITEM_TYPE_FASHION &&
                        stDropItem._astDropItem[i]._usItemConfigID == 8)
                    {
                        if (iTipsID <= 0)
                        {
                            iTipsID = 3030;
                        }
                        bUpdateRecord = true;
                    }

                    if (bUpdateRecord)
                    {
                        stRecordUnit.Clear();
                        stRecordUnit._ucItemType =
                            stDropItem._astDropItem[i]._ucItemType;
                        stRecordUnit._usItemConfigID =
                            stDropItem._astDropItem[i]._usItemConfigID;
                        stRecordUnit._iItemCount =
                            stDropItem._astDropItem[i]._iItemCount;
                        stRecordUnit._iUpdateTime = iNowTime;
                        stRecordUnit._uiGID = uiGID;

                        stZoneData._astSDRecord.Update(stRecordUnit);
                    }
                }

                if (iTipsID > 0)
                {
                    MsgTips stTips;
                    stTips.set_type(iTipsID);
                    stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
                    stDropItem.GetPBMsg(uiGID, *(stTips.mutable_bonus()));
                    CMainCtrl::m_pstMain->SendOnlineTips(stTips);
                }

                CMainCtrl::m_pstMain->m_stRewardBackMgr.UpdateZoneDataToDB();
            }
        }
        break;

    case SPLENDID_ACT_ID_19:	//摇摇乐活动
        {
            //因为有数值性的奖励 这里必须先判断背包格子
            if (stPlayerOnlineData._stUserStorage.GetBagEmptyGridCount() < 1)
            {
                return ERROR_STORAGE_BAG_IS_FULL;
            }

            int iGiftID = 0;
            int iNowTime = CMainCtrl::m_pstMain->m_iNow;
            CZoneData& stZoneData =
                CMainCtrl::m_pstMain->m_stZoneOnlineData._stZoneData;

            switch (iPos) 
            {
                case 0://摇奖
                    {
                        if (_stSplendidActConfigDetail._iRockGold > 0 &&
                            stPlayerBaseInfo._iGold < _stSplendidActConfigDetail._iRockGold)
                        {
                            return ERROR_GOLD_LESS;
                        }

                        _stSplendidActConfigDetail._aiRockRandomInt.Clear();
                        for (int i = 0; i < _stSplendidActConfigDetail._aiRockRandomInt.GetCount(); ++i)
                        {
                            _stSplendidActConfigDetail._aiRockRandomInt.AddOneItem(
                                CT_RANDOM_NUM->GetRand(MAX_SPLENDID_ROCK_NUM_COUNT)+1);
                        }

                        if (_stSplendidActConfigDetail._aiRockRandomInt.Size() !=
                            _stSplendidActConfigDetail._aiRockRandomInt.GetCount())
                        {
                            CT_ERROR((""));
                            return RET_SYS_ERROR;
                        }

                        bool bIsSameNum = true;
                        for (int i = 0; i < _stSplendidActConfigDetail._aiRockRandomInt.Size(); ++i)
                        {
                            if (_stSplendidActConfigDetail._aiRockRandomInt[0] !=
                                _stSplendidActConfigDetail._aiRockRandomInt[i])
                            {
                                bIsSameNum = false;
                                break;
                            }
                        }

                        iRet = CMainCtrl::m_pstMain->m_stItemMgr.SubGold(
                            stPlayerBaseInfo, OSS_MONEY_MODULE_58,
                            _stSplendidActConfigDetail._iRockGold);
                        CHECK_RETURN(iRet);
                        CMainCtrl::m_pstMain->m_stNotifyMgr.Notify(
                            stPlayerBaseInfo._uiGID, NOTIFY_USER_MONEY);

#define MACRO_SPLENDID_ROCK_SCORE_FOR_BIG 100

                        //0 小奖包(普通组合) 1 大奖包A(图片相同且没得大奖) 2 大奖包B(图片相同且已得大奖)
                        if (!bIsSameNum)
                        {
                            iGiftID = _stSplendidActConfigDetail._aiRockRandomGift[0];
                        }
                        else if (stActEx1Data._iRockScoreSum >= MACRO_SPLENDID_ROCK_SCORE_FOR_BIG &&
                                 stActEx1Data._ucRockBigBonus <= 0)
                        {
                            iGiftID = _stSplendidActConfigDetail._aiRockRandomGift[1];
                        }
                        else
                        {
                            iGiftID = _stSplendidActConfigDetail._aiRockRandomGift[2];
                        }

                        ++stActEx1Data._iRockScore;
                        ++stActEx1Data._iRockScoreSum;
                    }
                    break;

                default: //其他数值表示兑换
                    {
                        if (iPos <= 0 || iPos > MAX_SPLENDID_ROCK_EXCHANGE_GIFT)
                        {
                            CT_ERROR(("pos %d", iPos));
                            return RET_SYS_ERROR;
                        }

                        if (_stSplendidActConfigDetail._aiRockExchangeScore[iPos-1] > 0 &&
                            stActEx1Data._iRockScore < _stSplendidActConfigDetail._aiRockExchangeScore[iPos-1])
                        {
                            return ERROR_SPLENDID_ACT_NOT_FINISHED;
                        }

                        if (_stSplendidActConfigDetail._aiRockExchangeMask[iPos-1] > 0 &&
                            (int)stActEx1Data._aucRockExchange[iPos-1] >= _stSplendidActConfigDetail._aiRockExchangeMask[iPos-1])
                        {
                            return ERROR_SPLENDID_ACT_HAS_GET_MAX;
                        }
                        
                        iGiftID = _stSplendidActConfigDetail._aiRockExchangeGift[iPos-1];

                        if (_stSplendidActConfigDetail._aiRockExchangeScore[iPos-1] > 0)
                        {
                            stActEx1Data._iRockScore -= _stSplendidActConfigDetail._aiRockExchangeScore[iPos-1];
                        }

                        if (_stSplendidActConfigDetail._aiRockExchangeMask[iPos-1] > 0)
                        {
                            ++stActEx1Data._aucRockExchange[iPos-1];
                        }
                    }
                    break;
            }

            if (iGiftID > 0) 
            {
                if (0 == iPos)
                {
                    iRet = CMainCtrl::m_pstMain->m_stItemMgr.GetGiftItem(iGiftID, uiGID, stDropItem, false);
                    if (iRet) //必须错误日志 扣了玩家符石
                    {
                        CT_ERROR(("RockAct role(%u) get gift(%d) item error(%d)!", uiGID, iGiftID, iRet));
                        return iRet;
                    }
                }
                else
                {
                    CDropItemData stDropItemData;
                    stDropItemData._usItemConfigID = iGiftID;
                    stDropItemData._iItemCount = 1;
                    stDropItemData._ucItemType = ITEM_TYPE_GIFT;
                    stDropItem.Drop(stDropItemData);
                }

                iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem, true);
                if (iRet) //必须错误日志 扣了玩家符石
                {
                    CT_ERROR(("RockAct role(%u) drop gift(%d) item error(%d)!", uiGID, iGiftID, iRet));
                    return iRet;
                }

                int iTipsID = 0;
                bool bUpdateRecord = false;
                CSDRecordUnit stRecordUnit;

                switch (iGiftID)//兑换礼包的跑马灯
                {
                    case 515:
                    case 667:
                    case 485:
                    case 62:
                    case 652:
                    case 655:
                    {
                        iTipsID = 3035;
                    }
                    default:
                        break;
                }

#define MACRO_SPLENDID_ROCK_NO_ONE_TIME 86400*365 //置顶项 这里偷懒 取向后推一年

                for (int i = 0; i < stDropItem._astDropItem.Size(); ++i)
                {
                    bUpdateRecord = false;
                    if (stDropItem._astDropItem[i]._ucItemType == ITEM_TYPE_GIFT)
                    {
                        switch (stDropItem._astDropItem[i]._usItemConfigID)
                        {
                        case 48:
                        case 174:
                        case 632:
                        case 633:
                            if (iTipsID <= 0)
                            {
                                iTipsID = 3033;
                            }
                            bUpdateRecord = true;
                            break;
                        case 654:
                            if (iTipsID <= 0)
                            {
                                iTipsID = 3034;
                            }
                            bUpdateRecord = true;
                            iNowTime = CMainCtrl::m_pstMain->m_iNow + MACRO_SPLENDID_ROCK_NO_ONE_TIME;
                            break;
                        case 346:
                        case 655:
                            if (iTipsID <= 0)
                            {
                                iTipsID = 3034;
                            }
                            bUpdateRecord = true;
                            break;
                        default:
                            break;
                        }
                    }
                    else if ((stDropItem._astDropItem[i]._ucItemType == ITEM_TYPE_FASHION &&
                              stDropItem._astDropItem[i]._usItemConfigID == 11) ||
                             (stDropItem._astDropItem[i]._ucItemType == ITEM_TYPE_SILVER))
                    {
                        if (iTipsID <= 0)
                        {
                            iTipsID = 3034;
                        }
                        bUpdateRecord = true;
                    }
                    else if ((stDropItem._astDropItem[i]._ucItemType == ITEM_TYPE_PARTNER &&
                              stDropItem._astDropItem[i]._usItemConfigID == 34))
                    {
                        if (iTipsID <= 0)
                        {
                            iTipsID = 3034;
                        }
                        bUpdateRecord = true;
                        iNowTime = CMainCtrl::m_pstMain->m_iNow + MACRO_SPLENDID_ROCK_NO_ONE_TIME;
                        ++stActEx1Data._ucRockBigBonus;
                    }

                    if (bUpdateRecord)
                    {
                        stRecordUnit.Clear();
                        stRecordUnit._ucItemType =
                            stDropItem._astDropItem[i]._ucItemType;
                        stRecordUnit._usItemConfigID =
                            stDropItem._astDropItem[i]._usItemConfigID;
                        stRecordUnit._iItemCount =
                            stDropItem._astDropItem[i]._iItemCount;
                        stRecordUnit._iUpdateTime = iNowTime;
                        stRecordUnit._uiGID = uiGID;

                        stZoneData._astRockRecord.Update(stRecordUnit);

                        CMainCtrl::m_pstMain->m_stRewardBackMgr.UpdateZoneDataToDB();
                    }
                }

                if (iTipsID > 0)
                {
                    MsgTips stTips;
                    stTips.set_type(iTipsID);
                    stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
                    stDropItem.GetPBMsg(uiGID, *(stTips.mutable_bonus()));
                    CMainCtrl::m_pstMain->SendOnlineTips(stTips);
                }
            }
        }
        break;

    case SPLENDID_ACT_ID_20: //领红包活动
        {
            CSplendidActConfigData stConfigData;
            iRet = _stSplendidActConfig.GetConfig(SPLENDID_ACT_ID_20, stConfigData);
            if (iRet)
            {
                CT_ERROR(("get splendid act(%d) config error(%d)", SPLENDID_ACT_ID_20, iRet));
                return RET_SYS_NULL_POINTER;
            }

            if (CMainCtrl::m_pstMain->m_iNow < _stSplendidActConfigDetail._iRedPacketGatherStart)
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            if (stActEx1Data._iRedPacketGatherTime >= _stSplendidActConfigDetail._iRedPacketGatherStart)
            {
                return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
            }

            int iBeginZeroSec = CTTimeUtils::GetDayBeginSec(stConfigData._iBeginTime);
            int iEndZeroSec = CTTimeUtils::GetDayBeginSec(stConfigData._iEndTime);

            int iDayIndex = (iEndZeroSec - iBeginZeroSec) / 86400;

            int iTotalGold = 0;
            int iTotalSilver = 0;
            int64 i64RatioTmp = 0;
            for (int i = 0; i <= iDayIndex && i < MAX_SPLENDID_RED_PACKET_ACT_DAY_COUNT &&
                    i < MAX_SPLENDID_RED_PACKET_DB_DAY_COUNT; ++i)
            { 
                i64RatioTmp = INT64_1 * stActEx1Data._astRedPacket[i]._iGold * MAX_SPLENDID_RED_PACKET_BACK_RATIO;
                i64RatioTmp /= BATTLE_RATE_SKILL_PERCENT;

                iTotalGold += (int)(i64RatioTmp);

                i64RatioTmp = INT64_1 * stActEx1Data._astRedPacket[i]._iSilver * MAX_SPLENDID_RED_PACKET_BACK_RATIO;
                i64RatioTmp /= BATTLE_RATE_SKILL_PERCENT;

                iTotalSilver += (int)(i64RatioTmp);
            }
            
            if (iTotalGold > 0 || iTotalSilver > 0)
            {
                if (iTotalGold > 0)
                {
                    stDropItem.DropItem(ITEM_TYPE_GOLD, iTotalGold);
                }
                if (iTotalSilver > 0)
                {
                    stDropItem.DropItem(ITEM_TYPE_SILVER, iTotalSilver);
                }

                stDropItem.SetOssModule(OSS_MODULE_RED_PACKET);

                iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem, true);
                if (iRet) //必须错误日志
                {
                    CT_ERROR(("RedPacket role(%u) drop gold(%d) silver(%d) error(%d)!", uiGID, iTotalGold, iTotalSilver,
                        iRet));
                }

                CT_INFO(("RedPacketGather role(%u) gold(%d) silver(%d) time(%d)", uiGID, iTotalGold, iTotalSilver,
                    CMainCtrl::m_pstMain->m_iNow));
            }

            stActEx1Data._iRedPacketGatherTime = CMainCtrl::m_pstMain->m_iNow;
        }
        break;

    default:
        {
            if (stActData.HasGetBonus(iActID))
            {
                return ERROR_SPLENDID_ACT_HAS_GET_BONUS;
            }

            if (!stActData.HasFinished(iActID))
            {
                return ERROR_SPLENDID_ACT_NOT_FINISHED;
            }

            iGiftID = atoi(stConfigData._szBonus());
            iRet = CMainCtrl::m_pstMain->m_stStorageMgr.OpenGift(
                stPlayerOnlineData._stUserStorage, iGiftID, uiGID, stDropItem);
            CHECK_RETURN(iRet);

            stActData.SetGetBonus(iActID);
        }
        break;
    }

    stDropItem.GetPBMsg(uiGID, *(stAns.mutable_bonus()));
    UpdateSplendidActData(uiGID);

    if (SPLENDID_ACT_ID_18 == iActID || SPLENDID_ACT_ID_19 == iActID || SPLENDID_ACT_ID_20 == iActID)
    {
        CMainCtrl::m_pstMain->m_stRewardBackMgr.UpdateDetailEx1ToDB(
            stPlayerDetailEx1);
    }
    
    if (stConfigData._bHasChildAct) 
    {
        GetSplendidActListInfo(stActData, uiGID, stAns);
    }
    
    GetSplendidActDetailInfo(stActData, uiGID, iActID, stConfigData, stAns);

    return 0;
}

void CActMgr::SendSplendidActListToFront(CSplendidAct& stActData, unsigned int uiGID)
{
    if (!CMainCtrl::m_pstMain->m_stPlayerOnline.CheckOnline(uiGID))
    {
        return;
    }

    PBMsgHead stMsgHead;
    stMsgHead.set_time(CMainCtrl::m_pstMain->m_iNow);
    stMsgHead.set_msgact(0);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);
    stMsgHead.set_msgid(ID_MAIN_SPLENDID_ACT);
    stMsgHead.set_msgret(RET_OK);

    MsgAnsSplendidAct stAns;
    stAns.set_opt(1);

    GetSplendidActListInfo(stActData, uiGID, stAns);

    //发送数据
    CMainCtrl::m_pstMain->m_stEncodeBuf.Clear();
    CMainCtrl::m_pstMain->EncodePBMsg(stMsgHead, CMainCtrl::m_pstMain->m_stEncodeBuf);
    CMainCtrl::m_pstMain->EncodePBMsg(stAns, CMainCtrl::m_pstMain->m_stEncodeBuf);
    CMainCtrl::m_pstMain->NotifyOnlineUser(uiGID, CMainCtrl::m_pstMain->m_stEncodeBuf);
}

void CActMgr::SendSplendidActDetailInfoToFront(CSplendidAct& stActData, unsigned int uiGID, int iActID)
{
    if (!CMainCtrl::m_pstMain->m_stPlayerOnline.CheckOnline(uiGID))
    {
        return;
    }

    PBMsgHead stMsgHead;
    stMsgHead.set_time(CMainCtrl::m_pstMain->m_iNow);
    stMsgHead.set_msgact(0);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);
    stMsgHead.set_msgid(ID_MAIN_SPLENDID_ACT);
    stMsgHead.set_msgret(RET_OK);

    MsgAnsSplendidAct stAns;
    stAns.set_opt(2);

    CSplendidActConfigData stConfigData;
    int iRet = _stSplendidActConfig.GetConfig(iActID, stConfigData);
    if (iRet)
    {
        CT_WARNING(("%d", iActID));
        return;
    }

    GetSplendidActDetailInfo(stActData, uiGID, iActID, stConfigData, stAns);

    //发送数据
    CMainCtrl::m_pstMain->m_stEncodeBuf.Clear();
    CMainCtrl::m_pstMain->EncodePBMsg(stMsgHead, CMainCtrl::m_pstMain->m_stEncodeBuf);
    CMainCtrl::m_pstMain->EncodePBMsg(stAns, CMainCtrl::m_pstMain->m_stEncodeBuf);
    CMainCtrl::m_pstMain->NotifyOnlineUser(uiGID, CMainCtrl::m_pstMain->m_stEncodeBuf);
}

void CActMgr::NotifyActListToSelf(unsigned int uiGID)
{
    CCmdInnerActTitle* pstCmd =
        (CCmdInnerActTitle*)CT_CMDFACTORY->CreateCmd(ID_MAIN_INNER_ACT_TITLE);
    if (!pstCmd){CT_ERROR(("create CCmdInnerActTitle error %u",uiGID));return;}

    pstCmd->pstMainCtrl = CMainCtrl::m_pstMain;
    pstCmd->_uiGID = uiGID;
    pstCmd->_iSubCmd = CMD_ACT_OPT_SUB_NOTIFY_ACT_LIST;
    pstCmd->Do(NULL);
}

void CActMgr::NotifyActListToAll()
{
    CCmdInnerActTitle* pstCmd =
        (CCmdInnerActTitle*)CT_CMDFACTORY->CreateCmd(
            ID_MAIN_INNER_ACT_TITLE);
    if (!pstCmd) {CT_ERROR(("Create CCmdInnerActTitle error!")); return;}
    
    pstCmd->pstMainCtrl = CMainCtrl::m_pstMain;
    pstCmd->_uiGID = 0;
    pstCmd->_iSubCmd = CMD_ACT_OPT_SUB_NOTIFY_ACT_LIST_TO_ALL;
    pstCmd->_iIndex = 0;
    CMainCtrl::m_pstMain->m_stPlayerOnline.GetAllOnlineUser(pstCmd->_auiAllGID);
    pstCmd->Do(NULL);
}

//唯一的获取全量活动列表的接口所需要的数据尽量通过数据准备传引用
void CActMgr::GetActList(CPlayerBaseInfo& stPlayerBase,
        CPlayerDetailInfo& stPlayerDetail, MsgTips& stTips)
{
    stTips.set_type(TIPS_ACT_LIST);
    _stActCfg.GetActList(stTips);

    int iIndex = 0;
    int iLuckyDiceCount = 0;
    int iMagicContriTimes = 0;

    int iMagicDoor = CActCfgData::ACT_OBJ_FRONT_STAT_BEFORE_OPEN;//星门召唤 默认值:未开始
    int iPayContri = CActCfgData::ACT_OBJ_FRONT_STAT_BEFORE_OPEN;//星门充能 默认值:未开始
    int iLuckyDice = CActCfgData::ACT_OBJ_FRONT_STAT_BEFORE_OPEN;//幸运闯关 默认值:未开始
    int iClanTree = CActCfgData::ACT_OBJ_FRONT_STAT_BEFORE_OPEN;//家族神树 默认值:未开始    
    int iClanBattle = 0;
    int iAcaCup = 0;        //学院杯状态

    //星门召唤 以及 星门充能
    iIndex = CMainCtrl::m_pstMain->m_stClanMgr.GetClanIndex(
        stPlayerDetail._uiGID);
    if (iIndex >= 0)
    {
        CClanEntry& stClanEntry =
            CMainCtrl::m_pstMain->m_stClanMgr._stClanEntryHash[iIndex];

        if ((stPlayerDetail._stUserClan._uiClanId == stClanEntry._uiClanId) &&
            !(stPlayerDetail._stUserClan.HasJoinedClanBefore() &&
                CTTimeUtils::IsSameDay(stPlayerDetail._stUserClan._iJoinTime,
                    CMainCtrl::m_pstMain->m_iNow, 0)))
        {
            CMainCtrl::m_pstMain->m_stMagicDoorMgr.CheckMagicDoorDataZero(
                stClanEntry);

            if (stClanEntry._stMagicDoor._chStatus > 0)
            {
                iMagicDoor = CActCfgData::ACT_OBJ_FRONT_STAT_RUNNING;
            }
            else
            {
                iMagicDoor = CActCfgData::ACT_OBJ_FRONT_STAT_BEFORE_OPEN;

                if (stClanEntry._stMagicDoor._stDailyCounts.Get(
                        CMainCtrl::m_pstMain->m_iNow) >=
                            CMagicDoorMgr::MAGIC_DOOR_OPEN_TIME_PER_DAY)
                {
                    iMagicDoor = CActCfgData::ACT_OBJ_FRONT_STAT_CLOSE_ALREADY;
                }
            }

            CMainCtrl::m_pstMain->m_stMagicDoorMgr.CheckPayContriTimes(
                stPlayerDetail, stClanEntry);
            iMagicContriTimes =
                CMainCtrl::m_pstMain->m_stMagicDoorMgr.GetPayContriTimes(
                    stPlayerDetail, true);

            if (iMagicContriTimes >= MAGIC_DOOR_MAX_PAY_TIMES)//已经结束
            {
                iPayContri = CActCfgData::ACT_OBJ_FRONT_STAT_CLOSE_ALREADY;
            }
            else
            {
                iPayContri = CActCfgData::ACT_OBJ_FRONT_STAT_RUNNING;//正在进行
            }
        }
    }

    iLuckyDiceCount = CMainCtrl::m_pstMain->m_stFamilyDiceMgr.GetDiceCount(
        stPlayerBase, stPlayerDetail);
    if (iLuckyDiceCount > 0)
    {
        iLuckyDice = CActCfgData::ACT_OBJ_FRONT_STAT_RUNNING;
    }
    else
    {
        iLuckyDice = CActCfgData::ACT_OBJ_FRONT_STAT_CLOSE_ALREADY;
    }

    iClanTree = CActCfgData::ACT_OBJ_FRONT_STAT_CLOSE_ALREADY;
    if (CMainCtrl::m_pstMain->m_stTreeMgr.CanDoTreeOpt(stPlayerBase,
            stPlayerDetail._stUserClan))
    {
        iClanTree = CActCfgData::ACT_OBJ_FRONT_STAT_RUNNING;
    }

    //家族战
    if (CMainCtrl::m_pstMain->m_stClanBattleMgr.IsBegin())
    {
        iClanBattle = CActCfgData::ACT_OBJ_FRONT_STAT_RUNNING;
    }
    else
    {
        if (!CMainCtrl::m_pstMain->m_stClanBattleMgr.IsCanAddRole())
        {
            int iSecOfDay = (CMainCtrl::m_pstMain->m_stTm.tm_sec +
                             CMainCtrl::m_pstMain->m_stTm.tm_min * 60 +
                             CMainCtrl::m_pstMain->m_stTm.tm_hour * 3600);
            if (iSecOfDay >= 70200 && iSecOfDay < 72000)
            {
                iClanBattle = CActCfgData::ACT_OBJ_FRONT_STAT_BEFORE_OPEN;
            }
            else
            {
                iClanBattle = CActCfgData::ACT_OBJ_FRONT_STAT_CLOSE_ALREADY;
            }
        }
        else
        {
            if (CMainCtrl::m_pstMain->m_stClanBattleMgr.HasEnter(
                    stPlayerBase._uiGID))
            {
                iClanBattle = CActCfgData::ACT_OBJ_FRONT_STAT_HAS_ENTER;
            }
            else
            {
                iClanBattle = CActCfgData::ACT_OBJ_FRONT_STAT_NOT_ENTER;
            }
        } 
    }

    //学院杯状态
    switch (CMainCtrl::m_pstMain->m_stAcaCupMgr.NowStat())
    {
    case ACA_CUP_STAT_NOT_OPEN:
        iAcaCup = CActCfgData::ACT_OBJ_FRONT_STAT_BEFORE_OPEN;
        break;
    case ACA_CUP_STAT_APPLY:
        {
            if (CMainCtrl::m_pstMain->m_stAcaCupMgr.HasApply(stPlayerBase._uiGID))
            {
                iAcaCup = CActCfgData::ACT_OBJ_FRONT_STAT_HAS_ENTER;
            }
            else
            {
                iAcaCup = CActCfgData::ACT_OBJ_FRONT_STAT_NOT_ENTER;
            }
        }
        break;
    case ACA_CUP_STAT_WAIT_FOR_FIRST:
        iAcaCup = CActCfgData::ACT_OJB_FRONT_STAT_WAIT_FOR_OPEN;
        break;
    case ACA_CUP_STAT_FIRST:
        iAcaCup = CActCfgData::ACT_OBJ_FRONT_STAT_ACA_CUP_FIRST;
        break;
    case ACA_CUP_STAT_SECOND:
        {
            int iTmp[MAX_ACA_CAP_SECOND_ROUND] = {
                                                    CActCfgData::ACT_OBJ_FRONT_STAT_ACA_CUP_SECOND_16,
                                                    CActCfgData::ACT_OBJ_FRONT_STAT_ACA_CUP_SECOND_8,
                                                    CActCfgData::ACT_OBJ_FRONT_STAT_ACA_CUP_SECOND_4,
                                                    CActCfgData::ACT_OBJ_FRONT_STAT_ACA_CUP_SECOND_2,
                                                    CActCfgData::ACT_OBJ_FRONT_STAT_ACA_CUP_SECOND_1
                                                 };

            if (CMainCtrl::m_pstMain->m_stAcaCupMgr.NowSecondRound() >= MAX_ACA_CAP_SECOND_ROUND)
            {
                iAcaCup = 0;
            }
            else
            {
                iAcaCup = iTmp[CMainCtrl::m_pstMain->m_stAcaCupMgr.NowSecondRound()];
            }
        }
        break;
    default:
        break;
    }

    MsgActInfo* pstActInfo = stTips.add_act();
    if (!pstActInfo)
    {
        CT_ERROR(("MsgActInfo add pointer null!"));
    }
    else
    {
        pstActInfo->set_act_id(ACT_ID_MAGIC_DOOR);//星门召唤
        pstActInfo->set_act_status(iMagicDoor);
    }

    pstActInfo = stTips.add_act();
    if (!pstActInfo)
    {
        CT_ERROR(("MsgActInfo add pointer null!"));
    }
    else
    {
        pstActInfo->set_act_id(ACT_ID_MAGIC_CONTRIBUTE);//星门充能
        pstActInfo->set_act_status(iPayContri);
    }

    pstActInfo = stTips.add_act();
    if (!pstActInfo)
    {
        CT_ERROR(("MsgActInfo add pointer null!"));
    }
    else
    {
        pstActInfo->set_act_id(ACT_ID_CLAN_DICE);//幸运闯关
        pstActInfo->set_act_status(iLuckyDice);
    }

    pstActInfo = stTips.add_act();
    if (!pstActInfo)
    {
        CT_ERROR(("MsgActInfo add pointer null!"));
    }
    else
    {
        pstActInfo->set_act_id(ACT_ID_CLAN_TREE);//家族神树
        pstActInfo->set_act_status(iClanTree);
    }
    pstActInfo = stTips.add_act();
    if (!pstActInfo)
    {
        CT_ERROR(("MsgActInfo add pointer null!"));
    }
    else
    {
        //家族转盘
        int iClanDial = CActCfgData::ACT_OBJ_FRONT_STAT_CLOSE_ALREADY;
        if (CMainCtrl::m_pstMain->m_stClanMgr.CanDoDailOpt(stPlayerBase,
                stPlayerDetail, CMainCtrl::m_pstMain->m_iNow))
        {
            iClanDial = CActCfgData::ACT_OBJ_FRONT_STAT_RUNNING;
        }
        pstActInfo->set_act_id(ACT_ID_CLAN_DAIL);
        pstActInfo->set_act_status(iClanDial);
    }

    iIndex = FindActCfg(ACT_ID_CLAN_BATTLE);//家族战
    if (iIndex >= 0)
    {
        CActCfgData& stActCfgData = GetActCfg(iIndex);
        pstActInfo = stTips.add_act();
        if (!pstActInfo)
        {
            CT_ERROR(("MsgActInfo add pointer null!"));
        }
        else
        {
            stActCfgData.GetActInfo(*pstActInfo, iClanBattle);
            CT_TRACE(("ClanBattleAct gid(%u) id(%d) status(%d) starttime(%d)",
                stPlayerBase._uiGID, pstActInfo->act_id(),
                pstActInfo->act_status(),pstActInfo->start_time()));
        }
    }

    iIndex = FindActCfg(ACT_ID_NEW_SALES); //开服特卖
    if (iIndex >= 0)
    {
        if (true == IsNewSalesOpen(stPlayerBase))
        {
            pstActInfo = stTips.add_act();
            if (!pstActInfo)
            {
                CT_ERROR(("MsgActInfo add pointer null!"));
            }
            else
            {
                pstActInfo->set_act_id(ACT_ID_NEW_SALES);
                pstActInfo->set_act_status(CActCfgData::ACT_OBJ_FRONT_STAT_RUNNING);
            }
        }
    }

    iIndex = FindActCfg(ACT_ID_ACA_CUP);//学院杯
    if (iIndex >= 0)
    {
        CActCfgData& stActCfgData = GetActCfg(iIndex);
        pstActInfo = stTips.add_act();
        if (!pstActInfo)
        {
            CT_ERROR(("MsgActInfo add pointer null!"));
        }
        else
        {
            stActCfgData.GetActInfo(*pstActInfo, iAcaCup);
            CT_TRACE(("ClanBattleAct gid(%u) id(%d) status(%d) starttime(%d)",
                stPlayerBase._uiGID, pstActInfo->act_id(),
                pstActInfo->act_status(),pstActInfo->start_time()));
        }
    }
}

void CActMgr::NotifyActListToRole(CPlayerBaseInfo& stPlayerBase,
        CPlayerDetailInfo& stPlayerDetail)
{
    MsgTips stTips;
    GetActList(stPlayerBase, stPlayerDetail, stTips);

    CMainCtrl::m_pstMain->NotifyOnlineUser(stPlayerDetail._uiGID, ID_MAIN_TIPS,
        stTips, false);
}

int CActMgr::GetActNextOpenTime (short shActID, int iNowTime, int & iNextOpenTime)
{
    iNextOpenTime = 0;
    int iIndex = CMainCtrl::m_pstMain->m_stActMgr.FindActCfg (shActID);
    if (iIndex < 0)
    {
        CT_ERROR(("%d", shActID));
        return ERROR_ACT_EMPTY_CFG;
    }

    CActCfgData & stActCfgData = GetActCfg(iIndex);

    //判读起止时间
    if (iNowTime > stActCfgData._iStopTime)
    {
        iNextOpenTime = 0;
        return 0;
    }

    struct tm stTm;
    CTTime stTime(iNowTime);    
    stTime.GetLocalTm(&stTm);  

    int iOffsetDay = 0;    
    for (iOffsetDay = 0; iOffsetDay < 7; iOffsetDay++)
    {
        if (stActCfgData.IsWeekOpenDay(stTm.tm_wday + iOffsetDay))
        {
            break;
        }
    }

    int iDayBeginSec = CTTimeUtils::GetSecOfDay(iNowTime);
    if (iOffsetDay > 0)
    {
        iNextOpenTime = iDayBeginSec + iOffsetDay*86400 + stActCfgData.GetSegBeginTime(1);
        return 0;
    }

    //判读每天的时间段
    if (stActCfgData._astSegTime.Size() <= 0)
    {
        iNextOpenTime = iDayBeginSec + iOffsetDay*86400;
    }
    else
    {   
        int iSegId = 0;
        for (; iSegId < stActCfgData._astSegTime.Size(); ++iSegId)
        {
            CActSegTime & stSeg = stActCfgData._astSegTime[iSegId];
            if (iDayBeginSec < stSeg._iStart)
            {
                iNextOpenTime = iDayBeginSec + stSeg._iStart;
                return 0;
            }
        }

        //明天开启的时间
        iNextOpenTime = iDayBeginSec + 86400 + stActCfgData.GetSegBeginTime(1);
    }

    return 0;
}

void CActMgr::SendGrowFundInfo(CPayActData& stPayActData, unsigned int uiGID)
{
    PBMsgHead stMsgHead;
    stMsgHead.set_time(CMainCtrl::m_pstMain->m_iNow);
    stMsgHead.set_msgid(ID_MAIN_GROW_FUND);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);
    stMsgHead.set_msgret(0);

    MsgAnsGrowFund stAns;
    stAns.set_opt(1);

    stAns.set_has_buy(stPayActData._ucHasBuyGrowFund);
    if (stPayActData._ucHasBuyGrowFund == 1)    //已经购买
    {
        for (int i = 0; i < MAX_GROW_FUND_TYPE; ++i)
        {
            stAns.add_has_get(stPayActData.HasGetPayFund(i) ? 1 : 0);
        }
    }

    CMainCtrl::m_pstMain->m_stEncodeBuf.Clear();
    CMainCtrl::m_pstMain->EncodePBMsg(stMsgHead, CMainCtrl::m_pstMain->m_stEncodeBuf);
    CMainCtrl::m_pstMain->EncodePBMsg(stAns, CMainCtrl::m_pstMain->m_stEncodeBuf);
    CMainCtrl::m_pstMain->NotifyOnlineUser(uiGID, CMainCtrl::m_pstMain->m_stEncodeBuf);
}

void CActMgr::GetFightForBoxInfo(CFightForBoxData& stUserData, MsgAnsTreasureBox& stAns)
{
    stAns.set_opt(1);
    stAns.set_is_start(stUserData._ucHasBegin);
    if (stUserData._ucHasBegin != 1)
    {
        return;
    }
    
    CTArray<int, MAX_FIGHT_FOR_BOX_BOX_COUNT> aiIndex;
    GetValidBoxIndex(stUserData, aiIndex);
    stAns.set_is_award(aiIndex.Size() == 0);
    stAns.set_my_eye(stUserData.GetEyeCount());
    stAns.set_eye_can_buy(MAX_FIGHT_FOR_BOX_CAN_BUY_EYE_COUNT - stUserData._ucHasBuyEyeCount);
    stAns.set_npc1_index(stUserData._aiAllNPC[0]);
    stAns.set_npc2_index(stUserData._aiAllNPC[1]);

    string s = "";
    int iBombCount = 0;
    int iDoubleCount = 0;
    for (int i = 0; i < stUserData._aucBoxStat.Size(); ++i)
    {
        s += (stUserData._aucBoxStat[i] == CFightForBoxConfig::BOX_TYPE_NULL ? "1" : "0");

        if (CFightForBoxConfig::BOX_TYPE_4 == stUserData._aucBoxStat[i])
        {
            iBombCount++;
        }
        else if (CFightForBoxConfig::BOX_TYPE_5 == stUserData._aucBoxStat[i])
        {
            iDoubleCount++;
        }
    }
    stAns.set_box_desc(s);

    MsgTreasureBoxInfo* pstMsgTreasureBoxInfo = stAns.mutable_base_info();
    pstMsgTreasureBoxInfo->set_bomb_num(iBombCount);
    pstMsgTreasureBoxInfo->set_double_num(iDoubleCount);
    pstMsgTreasureBoxInfo->set_my_point(stUserData._ashAllPoint[0]);
    pstMsgTreasureBoxInfo->set_npc1_point(stUserData._ashAllPoint[1]);
    pstMsgTreasureBoxInfo->set_npc2_point(stUserData._ashAllPoint[2]);
}

void CActMgr::SendFightForBoxInfoToFront(unsigned int uiGID, CFightForBoxData& stUserData)
{
    PBMsgHead stMsgHead;
    stMsgHead.set_time(CMainCtrl::m_pstMain->m_iNow);
    stMsgHead.set_msgact(0);
    stMsgHead.set_msgtype(CSMsgDef::EMT_ANSWER);
    stMsgHead.set_msgid(ID_MAIN_FIGHT_FOR_BOX);
    stMsgHead.set_msgret(RET_OK);

    MsgAnsTreasureBox stAns;
    GetFightForBoxInfo(stUserData, stAns);

    stAns.set_opt(6);

    //发送数据
    CMainCtrl::m_pstMain->m_stEncodeBuf.Clear();
    CMainCtrl::m_pstMain->EncodePBMsg(stMsgHead, CMainCtrl::m_pstMain->m_stEncodeBuf);
    CMainCtrl::m_pstMain->EncodePBMsg(stAns, CMainCtrl::m_pstMain->m_stEncodeBuf);
    CMainCtrl::m_pstMain->NotifyOnlineUser(uiGID, CMainCtrl::m_pstMain->m_stEncodeBuf);
}

int CActMgr::StartFightForBox(CFightForBoxData& stUserData)
{
    if (stUserData._ucHasBegin != 0)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR1;
    }
    
    //初始化箱子
    CTArray<unsigned char, MAX_FIGHT_FOR_BOX_BOX_COUNT> astBoxTemplate = _stFightForBoxConfig._aucBoxTypeTemplate;
    stUserData._aucBoxStat.Clear();

    while (astBoxTemplate.Size() > 0)
    {
        int iIndex = CT_RANDOM_NUM->GetRand(astBoxTemplate.Size());
        stUserData._aucBoxStat.AddOneItem(astBoxTemplate[iIndex]);
        astBoxTemplate.DelOneItem(iIndex);
    }
    
    //初始化NPC
    stUserData._aiAllNPC.Clear();
    CTArray<int, MAX_FIGHT_FOR_BOX_NPC_COUNT> aiAllNPC = _stFightForBoxConfig._aiAllNPC; 
    for (int i = 0; i < stUserData._aiAllNPC.GetCount(); ++i)
    {
        int iIndex = CT_RANDOM_NUM->GetRand(aiAllNPC.Size());
        stUserData._aiAllNPC.AddOneItem(aiAllNPC[iIndex]);
        aiAllNPC.DelOneItem(iIndex);
    }

    //初始化积分
    stUserData._ashAllPoint.m_iUsedCount = stUserData._ashAllPoint.GetCount();
    for (int i = 0; i < stUserData._ashAllPoint.Size(); ++i)
    {
        stUserData._ashAllPoint[i] = 0;
    }
    
    //初始化慧眼
    stUserData._ucHasBuyEyeCount = 0;
    stUserData._ucLeftEyeCount = 1;  //缺省一次
    stUserData._ucHasUsedEyeCount = 0;

    //初始化NPC等待回合状态
    stUserData._aucNPCStop2RoundStat.m_iUsedCount = stUserData._aucNPCStop2RoundStat.GetCount();
    for (int i = 0; i < stUserData._aucNPCStop2RoundStat.Size(); ++i)
    {
        stUserData._aucNPCStop2RoundStat[i] = 0;
    }
    
    //设置开始
    stUserData._ucHasBegin = 1;

    return 0;
}

void CActMgr::GetValidBoxIndex(CFightForBoxData& stUserData, CTArray<int, MAX_FIGHT_FOR_BOX_BOX_COUNT>& aiIndex)
{
    aiIndex.Clear();

    for (int i = 0; i < stUserData._aucBoxStat.Size(); ++i)
    {
        if (stUserData._aucBoxStat[i] != CFightForBoxConfig::BOX_TYPE_NULL)
        {
            aiIndex.AddOneItem(i);
        }
    }
}

int CActMgr::OpenFightForBox(CFightForBoxData& stUserData, unsigned int uiGID, int iBoxPos, MsgAnsTreasureBox& stAns)
{
    if (stUserData._ucHasBegin != 1)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR2;
    }

    //主角行动
    if (iBoxPos < 0 || iBoxPos >= MAX_FIGHT_FOR_BOX_BOX_COUNT
        || stUserData._aucBoxStat[iBoxPos] == CFightForBoxConfig::BOX_TYPE_NULL)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR3;
    }

    //获取相关信息
    int iBombCount = 0;
    int iDoubleCount = 0;
    for (int i = 0; i < stUserData._aucBoxStat.Size(); ++i)
    {
        if (CFightForBoxConfig::BOX_TYPE_4 == stUserData._aucBoxStat[i])
        {
            iBombCount++;
        }
        else if (CFightForBoxConfig::BOX_TYPE_5 == stUserData._aucBoxStat[i])
        {
            iDoubleCount++;
        }
    }

    //处理宝箱内容
    int iGetPoint = 0;
    bool bStop2Round = false;   //是否眩晕
    switch(stUserData._aucBoxStat[iBoxPos])
    {
    case CFightForBoxConfig::BOX_TYPE_1:
        iGetPoint += CFightForBoxConfig::BOX_TYPE1_POINT;
        break;
    case CFightForBoxConfig::BOX_TYPE_2:
        iGetPoint += CFightForBoxConfig::BOX_TYPE2_POINT;
        break;
    case CFightForBoxConfig::BOX_TYPE_3:
        iGetPoint += CFightForBoxConfig::BOX_TYPE3_POINT;
        break;
    case CFightForBoxConfig::BOX_TYPE_4:
        iBombCount--;
        bStop2Round = true;
        break;
    case CFightForBoxConfig::BOX_TYPE_5:
        iDoubleCount--;
        iGetPoint += stUserData._ashAllPoint[0];
        break;
    default:
        CT_ERROR((""));
        return RET_SYS_ERROR;
    }
    
    //设置状态
    unsigned char ucBoxContent = stUserData._aucBoxStat[iBoxPos];
    stUserData._aucBoxStat[iBoxPos] = CFightForBoxConfig::BOX_TYPE_NULL;
    stUserData._ashAllPoint[0] += iGetPoint;

    //设置返回
    MsgTreasureBoxAct* pstMsgTreasureBoxAct = stAns.add_act_list();
    pstMsgTreasureBoxAct->set_act_index(1);
    pstMsgTreasureBoxAct->set_dest_box_id(iBoxPos);
    pstMsgTreasureBoxAct->set_dest_box_type(ucBoxContent);
    pstMsgTreasureBoxAct->set_dest_box_point(iGetPoint);
    MsgTreasureBoxInfo* pstMsgTreasureBoxInfo = pstMsgTreasureBoxAct->mutable_base_info();
    pstMsgTreasureBoxInfo->set_bomb_num(iBombCount);
    pstMsgTreasureBoxInfo->set_double_num(iDoubleCount);
    pstMsgTreasureBoxInfo->set_my_point(stUserData._ashAllPoint[0]);
    pstMsgTreasureBoxInfo->set_npc1_point(stUserData._ashAllPoint[1]);
    pstMsgTreasureBoxInfo->set_npc2_point(stUserData._ashAllPoint[2]);

    //获取当前有效的箱子下标
    CTArray<int, MAX_FIGHT_FOR_BOX_BOX_COUNT> aiIndex;
    GetValidBoxIndex(stUserData, aiIndex);

    //NPC行动
    const unsigned char NPC_COUNT = 2;

    unsigned char ucNextNpcID = 1;
    while (aiIndex.Size() > 0)
    {
        if (stUserData._aucNPCStop2RoundStat[ucNextNpcID - 1] != 0) //被炸弹炸了
        {
            stUserData._aucNPCStop2RoundStat[ucNextNpcID - 1] = 0;

            //设置返回
            MsgTreasureBoxAct* pstMsgTreasureBoxAct = stAns.add_act_list();
            pstMsgTreasureBoxAct->set_act_index(ucNextNpcID + 1);
            pstMsgTreasureBoxAct->set_dest_box_id(-1);

            //下个NPC
            ucNextNpcID = ucNextNpcID + 1;
        }
        else //随机抽取宝箱
        {
            int iIndex = CT_RANDOM_NUM->GetRand(aiIndex.Size());
            int iNpcBoxPos = aiIndex[iIndex];
            aiIndex.DelOneItem(iIndex);

            int iNpcGetPoint = 0;
            switch(stUserData._aucBoxStat[iNpcBoxPos])
            {
            case CFightForBoxConfig::BOX_TYPE_1:
                iNpcGetPoint += CFightForBoxConfig::BOX_TYPE1_POINT;
                break;
            case CFightForBoxConfig::BOX_TYPE_2:
                iNpcGetPoint += CFightForBoxConfig::BOX_TYPE2_POINT;
                break;
            case CFightForBoxConfig::BOX_TYPE_3:
                iNpcGetPoint += CFightForBoxConfig::BOX_TYPE3_POINT;
                break;
            case CFightForBoxConfig::BOX_TYPE_4:
                iBombCount--;
                stUserData._aucNPCStop2RoundStat[ucNextNpcID - 1] = 1;
                break;
            case CFightForBoxConfig::BOX_TYPE_5:
                iDoubleCount--;
                iNpcGetPoint += stUserData._ashAllPoint[ucNextNpcID];
                break;
            default:
                CT_ERROR((""));
                return RET_SYS_ERROR;
            }

            //保存状态
            unsigned char ucBoxContent = stUserData._aucBoxStat[iNpcBoxPos];
            stUserData._aucBoxStat[iNpcBoxPos] = CFightForBoxConfig::BOX_TYPE_NULL;
            stUserData._ashAllPoint[ucNextNpcID] += iNpcGetPoint;

            //设置返回
            MsgTreasureBoxAct* pstMsgTreasureBoxAct = stAns.add_act_list();
            pstMsgTreasureBoxAct->set_act_index(ucNextNpcID + 1);
            pstMsgTreasureBoxAct->set_dest_box_id(iNpcBoxPos);
            pstMsgTreasureBoxAct->set_dest_box_type(ucBoxContent);
            pstMsgTreasureBoxAct->set_dest_box_point(iNpcGetPoint);
            MsgTreasureBoxInfo* pstMsgTreasureBoxInfo = pstMsgTreasureBoxAct->mutable_base_info();
            pstMsgTreasureBoxInfo->set_bomb_num(iBombCount);
            pstMsgTreasureBoxInfo->set_double_num(iDoubleCount);
            pstMsgTreasureBoxInfo->set_my_point(stUserData._ashAllPoint[0]);
            pstMsgTreasureBoxInfo->set_npc1_point(stUserData._ashAllPoint[1]);
            pstMsgTreasureBoxInfo->set_npc2_point(stUserData._ashAllPoint[2]);

            //下个NPC
            ucNextNpcID = ucNextNpcID + 1;
        }

        if (ucNextNpcID > NPC_COUNT)
        {
            if (bStop2Round)        //主角眩晕了
            {
                bStop2Round = false;
                ucNextNpcID = 1;

                //设置返回
                MsgTreasureBoxAct* pstMsgTreasureBoxAct = stAns.add_act_list();
                pstMsgTreasureBoxAct->set_act_index(1);
                pstMsgTreasureBoxAct->set_dest_box_id(-1);
            }
            else                    //轮到主角行动了
            {
                break;
            }
        }
    }

    //检查活动是否结束
    if (aiIndex.Size() == 0)
    {
        //计算排名
        CTArray<unsigned char, MAX_FIGHT_FOR_BOX_ROLE_COUNT> aucRank;
       
        while (aucRank.Size() < aucRank.GetCount())
        {
            int iRoleIndex =  aucRank.Size();
            unsigned char ucRank = 1;
            short shMyPoint = stUserData._ashAllPoint[iRoleIndex];

            for (int i = 0; i < stUserData._ashAllPoint.Size(); ++i)
            {
                if (i == iRoleIndex)
                {
                    continue;
                }

                if (shMyPoint < stUserData._ashAllPoint[i])
                {
                    ucRank++;
                }
            }

            aucRank.AddOneItem(ucRank);
        }

        //发放精力
        int iBonusEnergy = 0;
        for (int i = 0; i < _stFightForBoxConfig._astRankBonus.Size(); ++i)
        {
            if (_stFightForBoxConfig._astRankBonus[i]._iRank == aucRank[0])
            {
                iBonusEnergy = _stFightForBoxConfig._astRankBonus[i]._iBonusEnergy;
            }
        }
        
        CDropItem stDropItem;
        stDropItem.DropEnergy(iBonusEnergy);
        stDropItem.SetOssModule(OSS_MODULE_FIGHT_FOR_BOX);
        CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);

        //发送排名给前台
        MsgTreasureBoxRank * pstRank = stAns.mutable_rank();
        pstRank->set_my_rank(aucRank[0]);
        pstRank->set_npc1_rank(aucRank[1]);
        pstRank->set_npc2_rank(aucRank[2]);
        pstRank->set_award_num(iBonusEnergy);

        //判断活动结束
        if (stUserData._ashAllPoint[0] == 0)
        {
            stUserData._ucHasBegin = 0;
        }
    }
    
    return 0;
}

int CActMgr::GetFightForBoxBonus(CFightForBoxData& stUserData, unsigned int uiGID, int iBonusID, bool bChangeAll, MsgAnsTreasureBox& stAns)
{
    int iRet = 0;

    if (stUserData._ucHasBegin != 1)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR2;
    }

    CTArray<int, MAX_FIGHT_FOR_BOX_BOX_COUNT> aiIndex;
    GetValidBoxIndex(stUserData, aiIndex);
    if (aiIndex.Size() > 0)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR9;
    }

    CDropItem stDropItem;
    short shMyPoint = stUserData._ashAllPoint[0];
    
    if (bChangeAll) //全部兑换成银币
    {
        stDropItem.DropSilver(shMyPoint * _stFightForBoxConfig._iOnePointToSilver);
        iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);

        //设置活动结束
        stUserData._ashAllPoint[0] = 0;
        stUserData._ucHasBegin = 0;

        //返回结果
        stDropItem.GetPBMsg(uiGID, *stAns.mutable_bonus_drop());

        return 0;
    }
    
    for (int i = 0; i < _stFightForBoxConfig._astExchangeBonus.Size(); ++i)
    {
        if (_stFightForBoxConfig._astExchangeBonus[i]._iID == iBonusID)
        {
            CFightForBoxBonusConfig & stBonusConfig = _stFightForBoxConfig._astExchangeBonus[i];
            if (stUserData._ashAllPoint[0] < stBonusConfig._iNeedPoint)
            {
                return ERROR_FIGHT_FOR_BOX_ERROR5;
            }

            shMyPoint -= stBonusConfig._iNeedPoint;
            stDropItem.Drop(stBonusConfig._stDropItemData);

            //将剩下的积分兑换成银币
            stDropItem.DropSilver(shMyPoint * _stFightForBoxConfig._iOnePointToSilver);
            shMyPoint = 0;

            stDropItem.SetOssModule(OSS_MODULE_FIGHT_FOR_BOX);
            iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
            if (iRet)
            {
                return iRet;
            }

            if (stBonusConfig._uiTips > 0)
            {
                MsgTips stTips;
                stTips.set_type(stBonusConfig._uiTips);
                stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
                CMainCtrl::m_pstMain->SendOnlineTips(stTips);
            }
            
            //设置活动结束
            stUserData._ashAllPoint[0] = 0;
            stUserData._ucHasBegin = 0;

            //返回结果
            stDropItem.GetPBMsg(uiGID, *stAns.mutable_bonus_drop());

            return 0;
        }
    }
    
    return ERROR_FIGHT_FOR_BOX_ERROR4;
}

int CActMgr::LookFightForBox(CFightForBoxData& stUserData, int iBoxPos, MsgAnsTreasureBox& stAns)
{
    if (stUserData._ucHasBegin != 1)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR2;
    }

    if (iBoxPos < 0 || iBoxPos >= MAX_FIGHT_FOR_BOX_BOX_COUNT
        || stUserData._aucBoxStat[iBoxPos] == CFightForBoxConfig::BOX_TYPE_NULL)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR3;
    }

    if (stUserData._ucHasUsedEyeCount >= 4)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR7;
    }

    if (stUserData._ucLeftEyeCount > 0)
    {
        stUserData._ucLeftEyeCount--;
    }
    else if (stUserData._ucBuyEyeCount > 0)
    {
        stUserData._ucBuyEyeCount--;
    }
    else
    {
        return ERROR_FIGHT_FOR_BOX_ERROR6;
    }
    
    stUserData._ucHasUsedEyeCount++;

    //返回结果
    stAns.set_my_eye(stUserData.GetEyeCount());
    stAns.set_dest_box_id(iBoxPos);
    stAns.set_dest_box_type(stUserData._aucBoxStat[iBoxPos]);

    return 0;
}

int CActMgr::FightForBoxBuyEye(CFightForBoxData& stUserData, CPlayerBaseInfo& stPlayerBaseInfo, MsgAnsTreasureBox& stAns)
{
    int iRet = 0;

    if (stUserData._ucHasBegin != 1)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR2;
    }
    
    if (stUserData._ucHasBuyEyeCount >= MAX_FIGHT_FOR_BOX_CAN_BUY_EYE_COUNT)
    {
        return ERROR_FIGHT_FOR_BOX_ERROR8;
    }
    
    iRet = CMainCtrl::m_pstMain->m_stItemMgr.SubGold(stPlayerBaseInfo, OSS_MONEY_MODULE_45, 20);
    CHECK_RETURN(iRet);

    CMainCtrl::m_pstMain->m_stNotifyMgr.Notify(stPlayerBaseInfo._uiGID, NOTIFY_USER_MONEY);

    stUserData._ucBuyEyeCount++;
    stUserData._ucHasBuyEyeCount++;

    //返回结果
    stAns.set_my_eye(stUserData.GetEyeCount());
    stAns.set_eye_can_buy(MAX_FIGHT_FOR_BOX_CAN_BUY_EYE_COUNT - stUserData._ucHasBuyEyeCount);

    return 0;
}

void CActMgr::GetNewZoneSalesInfo(CNewZoneSales & stUserData, MsgAnsNewZoneSales & stAns)
{
    for (int i = 0; i < _stNewZoneSalesConfig._astConfig.Size(); i++)
    {
        MsgSalesItem * pstItem = stAns.add_items();
        
        CNewZoneSalesItem & stItem = _stNewZoneSalesConfig._astConfig[i];
        pstItem->set_item_type(stItem._stItem._ucItemType);
        pstItem->set_item_config_id(stItem._stItem._usItemConfigID);
        pstItem->set_item_count(stItem._stItem._iItemCount);
        pstItem->set_initial_cost(stItem._iInitCost);
        pstItem->set_real_cost(stItem._iRealCost);
        pstItem->set_has_gained(stUserData.HasGained(stItem._stItem));
    }    

    if (false == stUserData._bGainedBonus &&  stUserData._astGainedItem.Size() == NEWZONE_SALES_ITEM_CNT)
    {
        stAns.set_can_get_bonus(true);
    }
    else
    {
        stAns.set_can_get_bonus(false);
    }

    stAns.set_end_time(GetStopTime(ACT_ID_NEW_SALES));
}

int CActMgr::BuyNewSalesItem (CPlayerBaseInfo & stPlayerBase, CNewZoneSales & stUserData, int iPos, CDropItem & stDropItem)
{
    CNewZoneSalesItem stItemCfg;
    int iRet = _stNewZoneSalesConfig.GetItemConfig(iPos, stItemCfg);
    CHECK_RETURN(iRet);

    if (stUserData.HasGained(stItemCfg._stItem))
    {
        return ERROR_NEWSALES_ITEM_REP;
    }    

    if (stPlayerBase._iGold < stItemCfg._iRealCost)
    {
        return ERROR_GOLD_LESS;
    }
        
    stDropItem.Drop(stItemCfg._stItem);
       
    iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, stPlayerBase._uiGID, stDropItem);
    CHECK_RETURN(iRet);

    CMainCtrl::m_pstMain->m_stItemMgr.SubGold(stPlayerBase, OSS_MONEY_MODULE_52, stItemCfg._iRealCost);

    iRet = stUserData.AddGainedItem(stItemCfg._stItem);
    if (iRet)
    {
        CT_ERROR(("%d, %d, %d", iRet, stPlayerBase._uiGID,iPos));
    }    

    if (stUserData.HasBuyAllItem())
    {
        stPlayerBase.SetActClose(ACT_BIT_NEWSALES1);
        stPlayerBase.SetActOpen (ACT_BIT_NEWSALES2);
    }

    return RET_OK;
}

int CActMgr::BuyNewSalesItemAll (CPlayerBaseInfo & stPlayerBase, CNewZoneSales & stUserData, CDropItem & stDropItem)
{    
    int iNeedGold = 0;

    for (int i = 0; i < _stNewZoneSalesConfig._astConfig.Size(); i++)
    {
        CNewZoneSalesItem & stItemCfg = _stNewZoneSalesConfig._astConfig[i];
        if ( false == stUserData.HasGained(stItemCfg._stItem))
        {
            iNeedGold += stItemCfg._iRealCost;
            stDropItem.Drop(stItemCfg._stItem);
        }
    }

    if (0 == iNeedGold)
    {
        return ERROR_NEWSALES_BONUS_REP;
    }    

    if (stPlayerBase._iGold < iNeedGold)
    {
        return ERROR_GOLD_LESS;
    }

    int iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, stPlayerBase._uiGID, stDropItem);
    CHECK_RETURN(iRet);

    CMainCtrl::m_pstMain->m_stItemMgr.SubGold(stPlayerBase, OSS_MONEY_MODULE_52, iNeedGold);

    for (int i = 0; i < stDropItem.Size(); i++)
    {
        CDropItemData & stItemData = stDropItem._astDropItem[i];
        iRet = stUserData.AddGainedItem(stItemData);
        if (iRet)
        {
            CT_ERROR(("%d, %d, %d", iRet, stPlayerBase._uiGID, stItemData._usItemConfigID));
        }   
    }
       
    stPlayerBase.SetActClose(ACT_BIT_NEWSALES1);
    stPlayerBase.SetActOpen (ACT_BIT_NEWSALES2);
    return RET_OK;
}

int CActMgr::GetNewSalesBonus (CPlayerBaseInfo & stPlayerBase,  CNewZoneSales & stUserData, CDropItem & stDropItem)
{
    unsigned int uiGID = stPlayerBase._uiGID;
    if (stUserData._astGainedItem.Size() !=  NEWZONE_SALES_ITEM_CNT)
    {
        return ERROR_NEWSALES_BONUS_NONE;
    }

    if (true == stUserData._bGainedBonus)
    {
        return ERROR_NEWSALES_BONUS_REP;
    }
    
    stDropItem.Drop(_stNewZoneSalesConfig._stBonus);
    
    int iRet = CMainCtrl::m_pstMain->m_stItemMgr.DropItem(NULL, uiGID, stDropItem);
    CHECK_RETURN(iRet);

    stUserData._bGainedBonus = true;    
    stPlayerBase.SetActClose(ACT_BIT_NEWSALES2);

    MsgTips stTips;
    stTips.set_type(1074);
    stTips.add_tip_argument(CMainCtrl::m_pstMain->m_stRoleMgr.GetRoleName(uiGID));
    CMainCtrl::m_pstMain->SendOnlineTips(stTips);

    return RET_OK;
}

bool CActMgr::IsNewSalesOpen(CPlayerBaseInfo & stPlayerBase)
{
    if (stPlayerBase._shLevel < NEWZONE_SALES_OPEN_LEVEL)
    {
        return false;
    }

    int iActEndTime = GetStopTime(ACT_ID_NEW_SALES);
    bool bIsActTimeEnd = (CMainCtrl::m_pstMain->m_iNow < iActEndTime ? false : true); //是否过了活动结束时间?
    bool bHasNotBuyAll = (CT_BIT_TEST(stPlayerBase._uiActStatus, ACT_BIT_NEWSALES1));  //是否还有物品没买完?
    bool bHasBonus = (CT_BIT_TEST(stPlayerBase._uiActStatus, ACT_BIT_NEWSALES2));  //是否有奖励未领?
    
    //活动打开的条件:  1.买完了物品, 还未领取奖励   2.时间未到期, 还未买完物品
    if ((true == bHasBonus)
        || (false == bIsActTimeEnd && true == bHasNotBuyAll))
    {
        return true;
    }
    
    return false;
}

